LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/gallery2 - galtheme.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 164 765 21.4 %
Date: 2013-07-09 Functions: 25 54 46.3 %
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 "sal/config.h"
      21             : 
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : #include <tools/vcompat.hxx>
      25             : #include <unotools/streamwrap.hxx>
      26             : #include <unotools/ucbstreamhelper.hxx>
      27             : #include <unotools/tempfile.hxx>
      28             : #include <unotools/localfilehelper.hxx>
      29             : #include <ucbhelper/content.hxx>
      30             : #include <sot/storage.hxx>
      31             : #include <sot/formats.hxx>
      32             : #include <sot/filelist.hxx>
      33             : #include <vcl/virdev.hxx>
      34             : #include <vcl/cvtgrf.hxx>
      35             : #include <svl/itempool.hxx>
      36             : #include <sfx2/docfile.hxx>
      37             : #include <avmedia/mediawindow.hxx>
      38             : #include <svx/svdograf.hxx>
      39             : #include <svx/fmpage.hxx>
      40             : #include "codec.hxx"
      41             : #include <svx/unomodel.hxx>
      42             : #include <svx/fmmodel.hxx>
      43             : #include <svx/fmview.hxx>
      44             : #include "svx/galmisc.hxx"
      45             : #include "svx/galtheme.hxx"
      46             : #include <com/sun/star/sdbc/XResultSet.hpp>
      47             : #include <com/sun/star/ucb/XContentAccess.hpp>
      48             : #include <com/sun/star/io/XInputStream.hpp>
      49             : #include "galobj.hxx"
      50             : #include <svx/gallery1.hxx>
      51             : #include "galtheme.hrc"
      52             : #include <vcl/lstbox.hxx>
      53             : #include "gallerydrawmodel.hxx"
      54             : 
      55             : // --------------
      56             : // - Namespaces -
      57             : // --------------
      58             : 
      59             : using namespace ::rtl;
      60             : using namespace ::com::sun::star;
      61             : 
      62             : // ------------
      63             : // - SgaTheme -
      64             : // ------------
      65             : DBG_NAME(GalleryTheme)
      66             : 
      67          22 : GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) :
      68             :         pParent               ( pGallery ),
      69             :         pThm                  ( pThemeEntry ),
      70             :         mnThemeLockCount      ( 0 ),
      71             :         mnBroadcasterLockCount( 0 ),
      72             :         nDragPos              ( 0 ),
      73          22 :         bDragging             ( sal_False )
      74             : {
      75             :     DBG_CTOR(GalleryTheme,NULL);
      76             : 
      77          22 :     ImplCreateSvDrawStorage();
      78          22 : }
      79             : 
      80             : // ------------------------------------------------------------------------
      81             : 
      82          66 : GalleryTheme::~GalleryTheme()
      83             : {
      84          22 :     ImplWrite();
      85             : 
      86         525 :     for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
      87             :     {
      88         503 :         GalleryObject* pEntry = aObjectList[ i ];
      89         503 :         Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
      90         503 :         Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
      91         503 :         delete pEntry;
      92             :     }
      93          22 :     aObjectList.clear();
      94             : 
      95             :     DBG_DTOR(GalleryTheme,NULL);
      96          44 : }
      97             : 
      98             : // ------------------------------------------------------------------------
      99             : 
     100          22 : void GalleryTheme::ImplCreateSvDrawStorage()
     101             : {
     102          22 :     aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), pThm->IsReadOnly() ? STREAM_READ : STREAM_STD_READWRITE );
     103             :     // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
     104          22 :     if ( ( aSvDrawStorageRef->GetError() != ERRCODE_NONE ) && !pThm->IsReadOnly() )
     105           0 :         aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     106          22 : }
     107             : 
     108             : // ------------------------------------------------------------------------
     109             : 
     110         503 : sal_Bool GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, size_t nPos, GalleryObject* pExistentEntry )
     111             : {
     112         503 :     SvStream*   pOStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
     113         503 :     sal_Bool        bRet = sal_False;
     114             : 
     115         503 :     if( pOStm )
     116             :     {
     117         503 :         const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END );
     118             : 
     119         503 :         rObj.WriteData( *pOStm, m_aDestDir );
     120             : 
     121         503 :         if( !pOStm->GetError() )
     122             :         {
     123             :             GalleryObject* pEntry;
     124             : 
     125         503 :             if( !pExistentEntry )
     126             :             {
     127         503 :                 pEntry = new GalleryObject;
     128         503 :                 if ( nPos < aObjectList.size() )
     129             :                 {
     130           0 :                     GalleryObjectList::iterator it = aObjectList.begin();
     131           0 :                     ::std::advance( it, nPos );
     132           0 :                     aObjectList.insert( it, pEntry );
     133             :                 }
     134             :                 else
     135         503 :                     aObjectList.push_back( pEntry );
     136             :             }
     137             :             else
     138           0 :                 pEntry = pExistentEntry;
     139             : 
     140         503 :             pEntry->aURL = rObj.GetURL();
     141         503 :             pEntry->nOffset = nOffset;
     142         503 :             pEntry->eObjKind = rObj.GetObjKind();
     143         503 :             bRet = sal_True;
     144             :         }
     145             : 
     146         503 :         delete pOStm;
     147             :     }
     148             : 
     149         503 :     return bRet;
     150             : }
     151             : 
     152             : // ------------------------------------------------------------------------
     153             : 
     154           0 : SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject* pEntry )
     155             : {
     156           0 :     SgaObject* pSgaObj = NULL;
     157             : 
     158           0 :     if( pEntry )
     159             :     {
     160           0 :         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     161             : 
     162           0 :         if( pIStm )
     163             :         {
     164             :             sal_uInt32 nInventor;
     165             : 
     166             :             // Ueberpruefen, ob das File ein gueltiges SGA-File ist
     167           0 :             pIStm->Seek( pEntry->nOffset );
     168           0 :             *pIStm >> nInventor;
     169             : 
     170           0 :             if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
     171             :             {
     172           0 :                 pIStm->Seek( pEntry->nOffset );
     173             : 
     174           0 :                 switch( pEntry->eObjKind )
     175             :                 {
     176           0 :                     case( SGA_OBJ_BMP ):    pSgaObj = new SgaObjectBmp(); break;
     177           0 :                     case( SGA_OBJ_ANIM ):   pSgaObj = new SgaObjectAnim(); break;
     178           0 :                     case( SGA_OBJ_INET ):   pSgaObj = new SgaObjectINet(); break;
     179           0 :                     case( SGA_OBJ_SVDRAW ): pSgaObj = new SgaObjectSvDraw(); break;
     180           0 :                     case( SGA_OBJ_SOUND ):  pSgaObj = new SgaObjectSound(); break;
     181             : 
     182             :                     default:
     183           0 :                     break;
     184             :                 }
     185             : 
     186           0 :                 if( pSgaObj )
     187             :                 {
     188           0 :                     *pIStm >> *pSgaObj;
     189           0 :                     pSgaObj->ImplUpdateURL( pEntry->aURL );
     190             :                 }
     191             :             }
     192             : 
     193           0 :             delete pIStm;
     194             :         }
     195             :     }
     196             : 
     197           0 :     return pSgaObj;
     198             : }
     199             : 
     200             : // ------------------------------------------------------------------------
     201             : 
     202          22 : void GalleryTheme::ImplWrite()
     203             : {
     204          22 :     if( IsModified() )
     205             :     {
     206          22 :         INetURLObject aPathURL( GetThmURL() );
     207             : 
     208          22 :         aPathURL.removeSegment();
     209          22 :         aPathURL.removeFinalSlash();
     210             : 
     211             :         DBG_ASSERT( aPathURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     212             : 
     213          22 :         if( FileExists( aPathURL ) || CreateDir( aPathURL ) )
     214             :         {
     215             : #ifdef UNX
     216          22 :             SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_COPY_ON_SYMLINK | STREAM_TRUNC );
     217             : #else
     218             :             SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
     219             : #endif
     220             : 
     221          22 :             if( pOStm )
     222             :             {
     223          22 :                 *pOStm << *this;
     224          22 :                 delete pOStm;
     225             :             }
     226             : 
     227          22 :             ImplSetModified( sal_False );
     228          22 :         }
     229             :     }
     230          22 : }
     231             : 
     232             : // ------------------------------------------------------------------------
     233             : 
     234           0 : const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
     235             : {
     236           0 :     for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
     237           0 :         if ( aObjectList[ i ]->aURL == rURL )
     238           0 :             return aObjectList[ i ];
     239           0 :     return NULL;
     240             : }
     241             : 
     242             : // ------------------------------------------------------------------------
     243             : 
     244           0 : INetURLObject GalleryTheme::ImplGetURL( const GalleryObject* pObject ) const
     245             : {
     246           0 :     INetURLObject aURL;
     247             : 
     248           0 :     if( pObject )
     249           0 :         aURL = pObject->aURL;
     250             : 
     251           0 :     return aURL;
     252             : }
     253             : 
     254             : // ------------------------------------------------------------------------
     255             : 
     256           0 : INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, sal_uIntPtr nFormat )
     257             : {
     258           0 :     INetURLObject   aDir( GetParent()->GetUserURL() );
     259           0 :     INetURLObject   aInfoFileURL( GetParent()->GetUserURL() );
     260           0 :     INetURLObject   aNewURL;
     261           0 :     sal_uInt32      nNextNumber = 1999;
     262           0 :     sal_Char const* pExt = NULL;
     263             :     sal_Bool            bExists;
     264             : 
     265           0 :     aDir.Append( String( RTL_CONSTASCII_USTRINGPARAM( "dragdrop" ) ) );
     266           0 :     CreateDir( aDir );
     267             : 
     268           0 :     aInfoFileURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "sdddndx1" ) ) );
     269             : 
     270             :     // read next possible number
     271           0 :     if( FileExists( aInfoFileURL ) )
     272             :     {
     273           0 :         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     274             : 
     275           0 :         if( pIStm )
     276             :         {
     277           0 :             *pIStm >> nNextNumber;
     278           0 :             delete pIStm;
     279             :         }
     280             :     }
     281             : 
     282             :     // create extension
     283           0 :     if( nFormat )
     284             :     {
     285           0 :         switch( nFormat )
     286             :         {
     287           0 :             case( CVT_BMP ): pExt = ".bmp"; break;
     288           0 :             case( CVT_GIF ): pExt = ".gif"; break;
     289           0 :             case( CVT_JPG ): pExt = ".jpg"; break;
     290           0 :             case( CVT_MET ): pExt = ".met"; break;
     291           0 :             case( CVT_PCT ): pExt = ".pct"; break;
     292           0 :             case( CVT_PNG ): pExt = ".png"; break;
     293           0 :             case( CVT_SVM ): pExt = ".svm"; break;
     294           0 :             case( CVT_TIF ): pExt = ".tif"; break;
     295           0 :             case( CVT_WMF ): pExt = ".wmf"; break;
     296           0 :             case( CVT_EMF ): pExt = ".emf"; break;
     297             : 
     298             :             default:
     299           0 :                 pExt = ".grf";
     300           0 :             break;
     301             :         }
     302             :     }
     303             : 
     304           0 :     do
     305             :     {
     306             :         // get URL
     307           0 :         if( SGA_OBJ_SVDRAW == eObjKind )
     308             :         {
     309           0 :             String aFileName( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/dd" ) );
     310           0 :             aNewURL = INetURLObject( aFileName += OUString::number( ++nNextNumber % 99999999 ), INET_PROT_PRIV_SOFFICE );
     311             : 
     312           0 :             bExists = sal_False;
     313             : 
     314           0 :             for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
     315           0 :                 if ( aObjectList[ i ]->aURL == aNewURL )
     316             :                 {
     317           0 :                     bExists = sal_True;
     318           0 :                     break;
     319           0 :                 }
     320             :         }
     321             :         else
     322             :         {
     323           0 :             String aFileName( RTL_CONSTASCII_USTRINGPARAM( "dd" ) );
     324             : 
     325           0 :             aFileName += OUString::number( ++nNextNumber % 999999 );
     326           0 :             aFileName += String( pExt, RTL_TEXTENCODING_ASCII_US );
     327             : 
     328           0 :             aNewURL = aDir;
     329           0 :             aNewURL.Append( aFileName );
     330             : 
     331           0 :             bExists = FileExists( aNewURL );
     332             :         }
     333             :     }
     334             :     while( bExists );
     335             : 
     336             :     // write updated number
     337           0 :     SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
     338             : 
     339           0 :     if( pOStm )
     340             :     {
     341           0 :         *pOStm << nNextNumber;
     342           0 :         delete pOStm;
     343             :     }
     344             : 
     345           0 :     return aNewURL;
     346             : }
     347             : 
     348             : // ------------------------------------------------------------------------
     349             : 
     350         503 : void GalleryTheme::ImplBroadcast( sal_uIntPtr nUpdatePos )
     351             : {
     352         503 :     if( !IsBroadcasterLocked() )
     353             :     {
     354         503 :         if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
     355         503 :             nUpdatePos = GetObjectCount() - 1;
     356             : 
     357         503 :         Broadcast( GalleryHint( GALLERY_HINT_THEME_UPDATEVIEW, GetName(), nUpdatePos ) );
     358             :     }
     359         503 : }
     360             : 
     361             : // ------------------------------------------------------------------------
     362             : 
     363           0 : sal_Bool GalleryTheme::UnlockTheme()
     364             : {
     365             :     DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
     366             : 
     367           0 :     sal_Bool bRet = sal_False;
     368             : 
     369           0 :     if( mnThemeLockCount )
     370             :     {
     371           0 :         --mnThemeLockCount;
     372           0 :         bRet = sal_True;
     373             :     }
     374             : 
     375           0 :     return bRet;
     376             : }
     377             : 
     378             : // ------------------------------------------------------------------------
     379             : 
     380           0 : void GalleryTheme::UnlockBroadcaster( sal_uIntPtr nUpdatePos )
     381             : {
     382             :     DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
     383             : 
     384           0 :     if( mnBroadcasterLockCount && !--mnBroadcasterLockCount )
     385           0 :         ImplBroadcast( nUpdatePos );
     386           0 : }
     387             : 
     388             : // ------------------------------------------------------------------------
     389             : 
     390         503 : bool GalleryTheme::InsertObject( const SgaObject& rObj, sal_uIntPtr nInsertPos )
     391             : {
     392         503 :     sal_Bool bRet = sal_False;
     393             : 
     394         503 :     if( rObj.IsValid() )
     395             :     {
     396         503 :         GalleryObject*  pFoundEntry = NULL;
     397         503 :         size_t iFoundPos = 0;
     398       16671 :         for ( size_t n = aObjectList.size(); iFoundPos < n; ++iFoundPos )
     399             :         {
     400       16168 :             if ( aObjectList[ iFoundPos ]->aURL == rObj.GetURL() )
     401             :             {
     402           0 :                 pFoundEntry = aObjectList[ iFoundPos ];
     403           0 :                 break;
     404             :             }
     405             :         }
     406             : 
     407         503 :         if( pFoundEntry )
     408             :         {
     409           0 :             GalleryObject aNewEntry;
     410             : 
     411             :             // update title of new object if necessary
     412           0 :             if( !rObj.GetTitle().Len() )
     413             :             {
     414           0 :                 SgaObject* pOldObj = ImplReadSgaObject( pFoundEntry );
     415             : 
     416           0 :                 if( pOldObj )
     417             :                 {
     418           0 :                     ( (SgaObject&) rObj ).SetTitle( pOldObj->GetTitle() );
     419           0 :                     delete pOldObj;
     420             :                 }
     421             :             }
     422           0 :             else if( rObj.GetTitle() == String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) ) )
     423           0 :                 ( (SgaObject&) rObj ).SetTitle( String() );
     424             : 
     425           0 :             ImplWriteSgaObject( rObj, nInsertPos, &aNewEntry );
     426           0 :             pFoundEntry->nOffset = aNewEntry.nOffset;
     427             :         }
     428             :         else
     429         503 :             ImplWriteSgaObject( rObj, nInsertPos, NULL );
     430             : 
     431         503 :         ImplSetModified( bRet = sal_True );
     432         503 :         ImplBroadcast( pFoundEntry ? iFoundPos : nInsertPos );
     433             :     }
     434             : 
     435         503 :     return bRet;
     436             : }
     437             : 
     438             : // ------------------------------------------------------------------------
     439             : 
     440           0 : SgaObject* GalleryTheme::AcquireObject( size_t nPos )
     441             : {
     442           0 :     return ImplReadSgaObject( aObjectList[ nPos ] );
     443             : }
     444             : 
     445             : // ------------------------------------------------------------------------
     446             : 
     447           0 : void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uIntPtr nPos, BitmapEx& rBitmapEx, Size& rSize, String& rTitle, String& rPath) const
     448             : {
     449           0 :     const GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : NULL;
     450             : 
     451           0 :     if(pGalleryObject)
     452             :     {
     453           0 :         rBitmapEx = pGalleryObject->maPreviewBitmapEx;
     454           0 :         rSize = pGalleryObject->maPreparedSize;
     455           0 :         rTitle = pGalleryObject->maTitle;
     456           0 :         rPath = pGalleryObject->maPath;
     457             :     }
     458             :     else
     459             :     {
     460             :         OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
     461             :     }
     462           0 : }
     463             : 
     464             : // ------------------------------------------------------------------------
     465             : 
     466           0 : void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uIntPtr nPos, const BitmapEx& rBitmapEx, const Size& rSize, const String& rTitle, const String& rPath)
     467             : {
     468           0 :     GalleryObject* pGalleryObject = nPos < aObjectList.size() ? aObjectList[ nPos ] : NULL;
     469             : 
     470           0 :     if(pGalleryObject)
     471             :     {
     472           0 :         pGalleryObject->maPreviewBitmapEx = rBitmapEx;
     473           0 :         pGalleryObject->maPreparedSize = rSize;
     474           0 :         pGalleryObject->maTitle = rTitle;
     475           0 :         pGalleryObject->maPath = rPath;
     476             :     }
     477             :     else
     478             :     {
     479             :         OSL_ENSURE(false, "OOps, no GalleryObject at this index (!)");
     480             :     }
     481           0 : }
     482             : 
     483             : // ------------------------------------------------------------------------
     484             : 
     485           0 : void GalleryTheme::ReleaseObject( SgaObject* pObject )
     486             : {
     487           0 :     delete pObject;
     488           0 : }
     489             : 
     490             : // ------------------------------------------------------------------------
     491             : 
     492           0 : bool GalleryTheme::RemoveObject( size_t nPos )
     493             : {
     494           0 :     GalleryObject* pEntry = NULL;
     495           0 :     if ( nPos < aObjectList.size() )
     496             :     {
     497           0 :         GalleryObjectList::iterator it = aObjectList.begin();
     498           0 :         ::std::advance( it, nPos );
     499           0 :         pEntry = *it;
     500           0 :         aObjectList.erase( it );
     501             :     }
     502             : 
     503           0 :     if( aObjectList.empty() )
     504           0 :         KillFile( GetSdgURL() );
     505             : 
     506           0 :     if( pEntry )
     507             :     {
     508           0 :         if( SGA_OBJ_SVDRAW == pEntry->eObjKind )
     509           0 :             aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     510             : 
     511           0 :         Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
     512           0 :         delete pEntry;
     513           0 :         Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
     514             : 
     515           0 :         ImplSetModified( sal_True );
     516           0 :         ImplBroadcast( nPos );
     517             :     }
     518             : 
     519           0 :     return( pEntry != NULL );
     520             : }
     521             : 
     522             : // ------------------------------------------------------------------------
     523             : 
     524           0 : bool GalleryTheme::ChangeObjectPos( size_t nOldPos, size_t nNewPos )
     525             : {
     526           0 :     sal_Bool bRet = sal_False;
     527             : 
     528           0 :     if(  nOldPos != nNewPos
     529           0 :       && nOldPos < aObjectList.size()
     530             :       )
     531             :     {
     532           0 :         GalleryObject* pEntry = aObjectList[ nOldPos ];
     533             : 
     534           0 :         GalleryObjectList::iterator it = aObjectList.begin();
     535           0 :         ::std::advance( it, nNewPos );
     536           0 :         aObjectList.insert( it, pEntry );
     537             : 
     538           0 :         if( nNewPos < nOldPos ) nOldPos++;
     539             : 
     540           0 :         it = aObjectList.begin();
     541           0 :         ::std::advance( it, nOldPos );
     542           0 :         aObjectList.erase( it );
     543             : 
     544           0 :         ImplSetModified( bRet = sal_True );
     545           0 :         ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) );
     546             :     }
     547             : 
     548           0 :     return bRet;
     549             : }
     550             : 
     551             : // ------------------------------------------------------------------------
     552             : 
     553           0 : void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress )
     554             : {
     555           0 :     if( !IsReadOnly() )
     556             :     {
     557           0 :         Graphic         aGraphic;
     558           0 :         String          aFormat;
     559             :         GalleryObject*  pEntry;
     560           0 :         const size_t    nCount = aObjectList.size();
     561             : 
     562           0 :         LockBroadcaster();
     563           0 :         bAbortActualize = sal_False;
     564             : 
     565             :         // LoeschFlag zuruecksetzen
     566           0 :         for (size_t i = 0; i < nCount; i++)
     567           0 :             aObjectList[ i ]->mbDelete = false;
     568             : 
     569           0 :         for(size_t i = 0; ( i < nCount ) && !bAbortActualize; i++)
     570             :         {
     571           0 :             if( pProgress )
     572           0 :                 pProgress->Update( i, nCount - 1 );
     573             : 
     574           0 :             pEntry = aObjectList[ i ];
     575             : 
     576           0 :             const INetURLObject aURL( pEntry->aURL );
     577             : 
     578           0 :             rActualizeLink.Call( (void*) &aURL );
     579             : 
     580             :             // SvDraw-Objekte werden spaeter aktualisiert
     581           0 :             if( pEntry->eObjKind != SGA_OBJ_SVDRAW )
     582             :             {
     583             :                 // Hier muss noch etwas eingebaut werden,
     584             :                 // das Files auf den ensprechenden Eintrag matched
     585             :                 // Grafiken als Grafik-Objekte in die Gallery aufnehmen
     586           0 :                 if( pEntry->eObjKind == SGA_OBJ_SOUND )
     587             :                 {
     588           0 :                     SgaObjectSound aObjSound( aURL );
     589           0 :                     if( !InsertObject( aObjSound ) )
     590           0 :                         pEntry->mbDelete = true;
     591             :                 }
     592             :                 else
     593             :                 {
     594           0 :                     aGraphic.Clear();
     595             : 
     596           0 :                     if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) )
     597             :                     {
     598             :                         SgaObject* pNewObj;
     599             : 
     600           0 :                         if ( SGA_OBJ_INET == pEntry->eObjKind )
     601           0 :                             pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat );
     602           0 :                         else if ( aGraphic.IsAnimated() )
     603           0 :                             pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat );
     604             :                         else
     605           0 :                             pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat );
     606             : 
     607           0 :                         if( !InsertObject( *pNewObj ) )
     608           0 :                             pEntry->mbDelete = true;
     609             : 
     610           0 :                         delete pNewObj;
     611             :                     }
     612             :                     else
     613           0 :                         pEntry->mbDelete = true; // Loesch-Flag setzen
     614             :                 }
     615             :             }
     616             :             else
     617             :             {
     618           0 :                 if ( aSvDrawStorageRef.Is() )
     619             :                 {
     620           0 :                     const String        aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
     621           0 :                     SvStorageStreamRef  pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ );
     622             : 
     623           0 :                     if( pIStm && !pIStm->GetError() )
     624             :                     {
     625           0 :                         pIStm->SetBufferSize( 16384 );
     626             : 
     627           0 :                         SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
     628             : 
     629           0 :                         if( !InsertObject( aNewObj ) )
     630           0 :                             pEntry->mbDelete = true;
     631             : 
     632           0 :                         pIStm->SetBufferSize( 0L );
     633           0 :                     }
     634             :                 }
     635             :             }
     636           0 :         }
     637             : 
     638             :         // remove all entries with set flag
     639           0 :         for ( size_t i = 0; i < aObjectList.size(); )
     640             :         {
     641           0 :             pEntry = aObjectList[ i ];
     642           0 :             if( pEntry->mbDelete )
     643             :             {
     644           0 :                 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
     645           0 :                 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uLong >( pEntry ) ) );
     646           0 :                 GalleryObjectList::iterator it = aObjectList.begin();
     647           0 :                 ::std::advance( it, i );
     648           0 :                 aObjectList.erase( it );
     649           0 :                 delete pEntry;
     650             :             }
     651           0 :             else ++i;
     652             :         }
     653             : 
     654             :         // update theme
     655           0 :         ::utl::TempFile aTmp;
     656           0 :         INetURLObject   aInURL( GetSdgURL() );
     657           0 :         INetURLObject   aTmpURL( aTmp.GetURL() );
     658             : 
     659             :         DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     660             :         DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     661             : 
     662           0 :         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     663           0 :         SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
     664             : 
     665           0 :         if( pIStm && pTmpStm )
     666             :         {
     667           0 :             for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
     668             :             {
     669           0 :                 pEntry = aObjectList[ i ];
     670             :                 SgaObject* pObj;
     671             : 
     672           0 :                 switch( pEntry->eObjKind )
     673             :                 {
     674           0 :                     case( SGA_OBJ_BMP ):    pObj = new SgaObjectBmp();      break;
     675           0 :                     case( SGA_OBJ_ANIM ):   pObj = new SgaObjectAnim();     break;
     676           0 :                     case( SGA_OBJ_INET ):   pObj = new SgaObjectINet();     break;
     677           0 :                     case( SGA_OBJ_SVDRAW ): pObj = new SgaObjectSvDraw();   break;
     678           0 :                     case (SGA_OBJ_SOUND):   pObj = new SgaObjectSound();    break;
     679             : 
     680             :                     default:
     681           0 :                         pObj = NULL;
     682           0 :                     break;
     683             :                 }
     684             : 
     685           0 :                 if( pObj )
     686             :                 {
     687           0 :                     pIStm->Seek( pEntry->nOffset );
     688           0 :                     *pIStm >> *pObj;
     689           0 :                     pEntry->nOffset = pTmpStm->Tell();
     690           0 :                     *pTmpStm << *pObj;
     691           0 :                     delete pObj;
     692             :                 }
     693             :             }
     694             :         }
     695             :         else
     696             :         {
     697             :             OSL_FAIL( "File(s) could not be opened" );
     698             :         }
     699             : 
     700           0 :         delete pIStm;
     701           0 :         delete pTmpStm;
     702             : 
     703           0 :         CopyFile( aTmpURL, aInURL );
     704           0 :         KillFile( aTmpURL );
     705             : 
     706           0 :         sal_uIntPtr nStorErr = 0;
     707             : 
     708             :         {
     709           0 :             SvStorageRef aTempStorageRef( new SvStorage( sal_False, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) );
     710           0 :             aSvDrawStorageRef->CopyTo( aTempStorageRef );
     711           0 :             nStorErr = aSvDrawStorageRef->GetError();
     712             :         }
     713             : 
     714           0 :         if( !nStorErr )
     715             :         {
     716           0 :             aSvDrawStorageRef.Clear();
     717           0 :             CopyFile( aTmpURL, GetSdvURL() );
     718           0 :             ImplCreateSvDrawStorage();
     719             :         }
     720             : 
     721           0 :         KillFile( aTmpURL );
     722           0 :         ImplSetModified( sal_True );
     723           0 :         ImplWrite();
     724           0 :         UnlockBroadcaster();
     725             :     }
     726           0 : }
     727             : 
     728             : // ------------------------------------------------------------------------
     729             : 
     730           0 : GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sal_Bool bReadOnly )
     731             : {
     732             :     DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
     733             : 
     734           0 :     GalleryThemeEntry*  pRet = NULL;
     735             : 
     736           0 :     if( FileExists( rURL ) )
     737             :     {
     738           0 :         SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
     739             : 
     740           0 :         if( pIStm )
     741             :         {
     742           0 :             String          aThemeName;
     743             :             sal_uInt16      nVersion;
     744           0 :             sal_Bool        bThemeNameFromResource = sal_False;
     745             : 
     746           0 :             *pIStm >> nVersion;
     747             : 
     748           0 :             if( nVersion <= 0x00ff )
     749             :             {
     750           0 :                 sal_uInt32      nThemeId = 0;
     751             : 
     752           0 :                 OString aTmpStr = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(*pIStm);
     753           0 :                 aThemeName = OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8);
     754             : 
     755             :                 // Charakterkonvertierung durchfuehren
     756           0 :                 if( nVersion >= 0x0004 )
     757             :                 {
     758             :                     sal_uInt32  nCount;
     759             :                     sal_uInt16  nTemp16;
     760             : 
     761           0 :                     *pIStm >> nCount >> nTemp16;
     762           0 :                     pIStm->Seek( STREAM_SEEK_TO_END );
     763             : 
     764             :                     // pruefen, ob es sich um eine neuere Version handelt;
     765             :                     // daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen,
     766             :                     // falls dies ueberhaupt moeglich ist
     767           0 :                     if( pIStm->Tell() >= 520 )
     768             :                     {
     769             :                         sal_uInt32 nId1, nId2;
     770             : 
     771           0 :                         pIStm->SeekRel( -520 );
     772           0 :                         *pIStm >> nId1 >> nId2;
     773             : 
     774           0 :                         if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
     775           0 :                             nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
     776             :                         {
     777           0 :                             VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ );
     778             : 
     779           0 :                             *pIStm >> nThemeId;
     780             : 
     781           0 :                             if( pCompat->GetVersion() >= 2 )
     782             :                             {
     783           0 :                                 *pIStm >> bThemeNameFromResource;
     784             :                             }
     785             : 
     786           0 :                             delete pCompat;
     787             :                         }
     788             :                     }
     789             :                 }
     790             : 
     791           0 :                 INetURLObject aPathURL( rURL );
     792             :                 pRet = new GalleryThemeEntry( aPathURL, aThemeName,
     793             :                                               bReadOnly, sal_False, nThemeId,
     794           0 :                                               bThemeNameFromResource );
     795             :             }
     796             : 
     797           0 :             delete pIStm;
     798             :         }
     799             :     }
     800             : 
     801           0 :     return pRet;
     802             : }
     803             : 
     804             : // -----------------------------------------------------------------------------
     805             : 
     806           0 : sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, BitmapEx& rBmp, sal_Bool )
     807             : {
     808           0 :     SgaObject*  pObj = AcquireObject( nPos );
     809           0 :     sal_Bool        bRet = sal_False;
     810             : 
     811           0 :     if( pObj )
     812             :     {
     813           0 :         rBmp = pObj->GetThumbBmp();
     814           0 :         ReleaseObject( pObj );
     815           0 :         bRet = sal_True;
     816             :     }
     817             : 
     818           0 :     return bRet;
     819             : }
     820             : 
     821             : // -----------------------------------------------------------------------------
     822             : 
     823           0 : sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool bProgress )
     824             : {
     825           0 :     const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
     826           0 :     sal_Bool                    bRet = sal_False;
     827             : 
     828           0 :     if( pObject )
     829             :     {
     830           0 :         const INetURLObject aURL( ImplGetURL( pObject ) );
     831             : 
     832           0 :         switch( pObject->eObjKind )
     833             :         {
     834             :             case( SGA_OBJ_BMP ):
     835             :             case( SGA_OBJ_ANIM ):
     836             :             case( SGA_OBJ_INET ):
     837             :             {
     838           0 :                 String aFilterDummy;
     839           0 :                 bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE );
     840             :             }
     841           0 :             break;
     842             : 
     843             :             case( SGA_OBJ_SVDRAW ):
     844             :             {
     845           0 :                 SvxGalleryDrawModel aModel;
     846             : 
     847           0 :                 if( aModel.GetModel() )
     848             :                 {
     849           0 :                     if( GetModel( nPos, *aModel.GetModel(), bProgress ) )
     850             :                     {
     851           0 :                         ImageMap aIMap;
     852             : 
     853           0 :                         if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
     854           0 :                             bRet = sal_True;
     855             :                         else
     856             :                         {
     857           0 :                             VirtualDevice aVDev;
     858           0 :                             aVDev.SetMapMode( MapMode( MAP_100TH_MM ) );
     859           0 :                             FmFormView aView( aModel.GetModel(), &aVDev );
     860             : 
     861           0 :                             aView.hideMarkHandles();
     862           0 :                             aView.ShowSdrPage(aView.GetModel()->GetPage(0));
     863           0 :                             aView.MarkAll();
     864           0 :                             rGraphic = aView.GetAllMarkedGraphic();
     865           0 :                             bRet = sal_True;
     866           0 :                         }
     867             :                     }
     868           0 :                 }
     869             :             }
     870           0 :             break;
     871             : 
     872             :             case( SGA_OBJ_SOUND ):
     873             :             {
     874           0 :                 SgaObject* pObj = AcquireObject( nPos );
     875             : 
     876           0 :                 if( pObj )
     877             :                 {
     878           0 :                     rGraphic = pObj->GetThumbBmp();
     879             :                     //Bitmap aBmp( pObj->GetThumbBmp() );
     880             :                     //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
     881             :                     //rGraphic = aBmp;
     882           0 :                     ReleaseObject( pObj );
     883           0 :                     bRet = sal_True;
     884             :                 }
     885             :             }
     886           0 :             break;
     887             : 
     888             :             default:
     889           0 :             break;
     890           0 :         }
     891             :     }
     892             : 
     893           0 :     return bRet;
     894             : }
     895             : 
     896             : // -----------------------------------------------------------------------------
     897             : 
     898           0 : sal_Bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_uIntPtr nInsertPos )
     899             : {
     900           0 :     sal_Bool bRet = sal_False;
     901             : 
     902           0 :     if( rGraphic.GetType() != GRAPHIC_NONE )
     903             :     {
     904           0 :         sal_uIntPtr           nExportFormat = CVT_UNKNOWN;
     905           0 :         const GfxLink   aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
     906             : 
     907           0 :         if( aGfxLink.GetDataSize() )
     908             :         {
     909           0 :             switch( aGfxLink.GetType() )
     910             :             {
     911           0 :                 case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break;
     912           0 :                 case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break;
     913           0 :                 case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break;
     914           0 :                 case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break;
     915           0 :                 case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break;
     916           0 :                 case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break;
     917           0 :                 case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break;
     918           0 :                 case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break;
     919           0 :                 case( GFX_LINK_TYPE_NATIVE_SVG ): nExportFormat = CVT_SVG; break;
     920             :                 default:
     921           0 :                     break;
     922             :             }
     923             :         }
     924             :         else
     925             :         {
     926           0 :             if( rGraphic.GetType() == GRAPHIC_BITMAP )
     927             :             {
     928           0 :                 if( rGraphic.IsAnimated() )
     929           0 :                     nExportFormat = CVT_GIF;
     930             :                 else
     931           0 :                     nExportFormat = CVT_PNG;
     932             :             }
     933             :             else
     934           0 :                 nExportFormat = CVT_SVM;
     935             :         }
     936             : 
     937           0 :         const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) );
     938           0 :         SvStream*           pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
     939             : 
     940           0 :         if( pOStm )
     941             :         {
     942           0 :             pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
     943             : 
     944           0 :             if( CVT_SVM == nExportFormat )
     945             :             {
     946           0 :                 GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
     947             : 
     948           0 :                 aMtf.Write( *pOStm );
     949           0 :                 bRet = ( pOStm->GetError() == ERRCODE_NONE );
     950             :             }
     951             :             else
     952             :             {
     953           0 :                 if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
     954             :                 {
     955           0 :                     pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
     956           0 :                     bRet = ( pOStm->GetError() == ERRCODE_NONE );
     957             :                 }
     958             :                 else
     959           0 :                     bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
     960             :             }
     961             : 
     962           0 :             delete pOStm;
     963             :         }
     964             : 
     965           0 :         if( bRet )
     966             :         {
     967           0 :             const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     968           0 :             InsertObject( aObjBmp, nInsertPos );
     969           0 :         }
     970             :     }
     971             : 
     972           0 :     return bRet;
     973             : }
     974             : 
     975             : // -----------------------------------------------------------------------------
     976             : 
     977           0 : sal_Bool GalleryTheme::GetModel( sal_uIntPtr nPos, SdrModel& rModel, sal_Bool )
     978             : {
     979           0 :     const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
     980           0 :     sal_Bool                    bRet = sal_False;
     981             : 
     982           0 :     if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
     983             :     {
     984           0 :         const INetURLObject aURL( ImplGetURL( pObject ) );
     985           0 :         SvStorageRef        xStor( GetSvDrawStorage() );
     986             : 
     987           0 :         if( xStor.Is() )
     988             :         {
     989           0 :             const String        aStmName( GetSvDrawStreamNameFromURL( aURL ) );
     990           0 :             SvStorageStreamRef  xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
     991             : 
     992           0 :             if( xIStm.Is() && !xIStm->GetError() )
     993             :             {
     994           0 :                 xIStm->SetBufferSize( STREAMBUF_SIZE );
     995           0 :                 bRet = GallerySvDrawImport( *xIStm, rModel );
     996           0 :                 xIStm->SetBufferSize( 0L );
     997           0 :             }
     998           0 :         }
     999             :     }
    1000             : 
    1001           0 :     return bRet;
    1002             : }
    1003             : 
    1004             : // -----------------------------------------------------------------------------
    1005             : 
    1006           0 : sal_Bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_uIntPtr nInsertPos )
    1007             : {
    1008           0 :     INetURLObject   aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
    1009           0 :     SvStorageRef    xStor( GetSvDrawStorage() );
    1010           0 :     sal_Bool            bRet = sal_False;
    1011             : 
    1012           0 :     if( xStor.Is() )
    1013             :     {
    1014           0 :         const String        aStmName( GetSvDrawStreamNameFromURL( aURL ) );
    1015           0 :         SvStorageStreamRef  xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
    1016             : 
    1017           0 :         if( xOStm.Is() && !xOStm->GetError() )
    1018             :         {
    1019           0 :             SvMemoryStream  aMemStm( 65535, 65535 );
    1020           0 :             FmFormModel*    pFormModel = (FmFormModel*) &rModel;
    1021             : 
    1022           0 :             pFormModel->BurnInStyleSheetAttributes();
    1023             : 
    1024             :             {
    1025           0 :                 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
    1026             : 
    1027           0 :                 if( xDocOut.is() )
    1028           0 :                     SvxDrawingLayerExport( pFormModel, xDocOut );
    1029             :             }
    1030             : 
    1031           0 :             aMemStm.Seek( 0 );
    1032             : 
    1033           0 :             xOStm->SetBufferSize( 16348 );
    1034           0 :             GalleryCodec aCodec( *xOStm );
    1035           0 :             aCodec.Write( aMemStm );
    1036             : 
    1037           0 :             if( !xOStm->GetError() )
    1038             :             {
    1039           0 :                 SgaObjectSvDraw aObjSvDraw( rModel, aURL );
    1040           0 :                 bRet = InsertObject( aObjSvDraw, nInsertPos );
    1041             :             }
    1042             : 
    1043           0 :             xOStm->SetBufferSize( 0L );
    1044           0 :             xOStm->Commit();
    1045           0 :         }
    1046             :     }
    1047             : 
    1048           0 :     return bRet;
    1049             : }
    1050             : 
    1051             : // -----------------------------------------------------------------------------
    1052             : 
    1053           0 : sal_Bool GalleryTheme::GetModelStream( sal_uIntPtr nPos, SotStorageStreamRef& rxModelStream, sal_Bool )
    1054             : {
    1055           0 :     const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
    1056           0 :     sal_Bool                    bRet = sal_False;
    1057             : 
    1058           0 :     if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
    1059             :     {
    1060           0 :         const INetURLObject aURL( ImplGetURL( pObject ) );
    1061           0 :         SvStorageRef        xStor( GetSvDrawStorage() );
    1062             : 
    1063           0 :         if( xStor.Is() )
    1064             :         {
    1065           0 :             const String        aStmName( GetSvDrawStreamNameFromURL( aURL ) );
    1066           0 :             SvStorageStreamRef  xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
    1067             : 
    1068           0 :             if( xIStm.Is() && !xIStm->GetError() )
    1069             :             {
    1070           0 :                 sal_uInt32 nVersion = 0;
    1071             : 
    1072           0 :                 xIStm->SetBufferSize( 16348 );
    1073             : 
    1074           0 :                 if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
    1075             :                 {
    1076           0 :                     SvxGalleryDrawModel aModel;
    1077             : 
    1078           0 :                     if( aModel.GetModel() )
    1079             :                     {
    1080           0 :                         if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
    1081             :                         {
    1082           0 :                             aModel.GetModel()->BurnInStyleSheetAttributes();
    1083             : 
    1084             :                             {
    1085           0 :                                 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
    1086             : 
    1087           0 :                                 if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
    1088           0 :                                     rxModelStream->Commit();
    1089             :                             }
    1090             :                         }
    1091             : 
    1092           0 :                         bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
    1093           0 :                     }
    1094             :                 }
    1095             : 
    1096           0 :                 xIStm->SetBufferSize( 0 );
    1097           0 :             }
    1098           0 :         }
    1099             :     }
    1100             : 
    1101           0 :     return bRet;
    1102             : }
    1103             : 
    1104             : // -----------------------------------------------------------------------------
    1105             : 
    1106           0 : sal_Bool GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, sal_uIntPtr nInsertPos )
    1107             : {
    1108           0 :     INetURLObject   aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
    1109           0 :     SvStorageRef    xStor( GetSvDrawStorage() );
    1110           0 :     sal_Bool            bRet = sal_False;
    1111             : 
    1112           0 :     if( xStor.Is() )
    1113             :     {
    1114           0 :         const String        aStmName( GetSvDrawStreamNameFromURL( aURL ) );
    1115           0 :         SvStorageStreamRef  xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
    1116             : 
    1117           0 :         if( xOStm.Is() && !xOStm->GetError() )
    1118             :         {
    1119           0 :             GalleryCodec    aCodec( *xOStm );
    1120           0 :             SvMemoryStream  aMemStm( 65535, 65535 );
    1121             : 
    1122           0 :             xOStm->SetBufferSize( 16348 );
    1123           0 :             aCodec.Write( *rxModelStream );
    1124             : 
    1125           0 :             if( !xOStm->GetError() )
    1126             :             {
    1127           0 :                 xOStm->Seek( 0 );
    1128           0 :                 SgaObjectSvDraw aObjSvDraw( *xOStm, aURL );
    1129           0 :                 bRet = InsertObject( aObjSvDraw, nInsertPos );
    1130             :             }
    1131             : 
    1132           0 :             xOStm->SetBufferSize( 0L );
    1133           0 :             xOStm->Commit();
    1134           0 :         }
    1135             :     }
    1136             : 
    1137           0 :     return bRet;
    1138             : }
    1139             : 
    1140             : // -----------------------------------------------------------------------------
    1141             : 
    1142           0 : sal_Bool GalleryTheme::GetURL( sal_uIntPtr nPos, INetURLObject& rURL, sal_Bool )
    1143             : {
    1144           0 :     const GalleryObject*    pObject = ImplGetGalleryObject( nPos );
    1145           0 :     sal_Bool                    bRet = sal_False;
    1146             : 
    1147           0 :     if( pObject )
    1148             :     {
    1149           0 :         rURL = INetURLObject( ImplGetURL( pObject ) );
    1150           0 :         bRet = sal_True;
    1151             :     }
    1152             : 
    1153           0 :     return bRet;
    1154             : }
    1155             : 
    1156             : // -----------------------------------------------------------------------------
    1157             : 
    1158         503 : sal_Bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_uIntPtr nInsertPos )
    1159             : {
    1160         503 :     Graphic         aGraphic;
    1161        1006 :     String          aFormat;
    1162         503 :     SgaObject*      pNewObj = NULL;
    1163         503 :     const sal_uInt16    nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
    1164         503 :     sal_Bool            bRet = sal_False;
    1165             : 
    1166         503 :     if( nImportRet != SGA_IMPORT_NONE )
    1167             :     {
    1168         468 :         if ( SGA_IMPORT_INET == nImportRet )
    1169           0 :             pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat );
    1170         468 :         else if ( aGraphic.IsAnimated() )
    1171           0 :             pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat );
    1172             :         else
    1173         468 :             pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat );
    1174             :     }
    1175          35 :     else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
    1176          35 :         pNewObj = (SgaObject*) new SgaObjectSound( rURL );
    1177             : 
    1178         503 :     if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
    1179         503 :         bRet = sal_True;
    1180             : 
    1181         503 :     delete pNewObj;
    1182             : 
    1183        1006 :     return bRet;
    1184             : }
    1185             : 
    1186             : // -----------------------------------------------------------------------------
    1187             : 
    1188           0 : sal_Bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_uIntPtr nInsertPos )
    1189             : {
    1190           0 :     INetURLObject                   aURL;
    1191           0 :     ::std::vector< INetURLObject >  aURLVector;
    1192           0 :     sal_Bool                            bRet = sal_False;
    1193             : 
    1194             :     try
    1195             :     {
    1196           0 :         ::ucbhelper::Content         aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
    1197           0 :         sal_Bool        bFolder = false;
    1198             : 
    1199           0 :         aCnt.getPropertyValue("IsFolder") >>= bFolder;
    1200             : 
    1201           0 :         if( bFolder )
    1202             :         {
    1203           0 :             uno::Sequence< OUString > aProps( 1 );
    1204           0 :             aProps.getArray()[ 0 ] = OUString("Url");
    1205           0 :             uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
    1206           0 :             uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
    1207           0 :             if( xContentAccess.is() )
    1208             :             {
    1209           0 :                 while( xResultSet->next() )
    1210             :                 {
    1211           0 :                     aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
    1212           0 :                     aURLVector.push_back( aURL );
    1213             :                 }
    1214           0 :             }
    1215             :         }
    1216             :         else
    1217           0 :             aURLVector.push_back( rFileOrDirURL );
    1218             :     }
    1219           0 :     catch( const ucb::ContentCreationException& )
    1220             :     {
    1221             :     }
    1222           0 :     catch( const uno::RuntimeException& )
    1223             :     {
    1224             :     }
    1225           0 :     catch( const uno::Exception& )
    1226             :     {
    1227             :     }
    1228             : 
    1229           0 :     ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() );
    1230             : 
    1231           0 :     while( aIter != aEnd )
    1232           0 :         bRet = bRet || InsertURL( *aIter++, nInsertPos );
    1233             : 
    1234           0 :     return bRet;
    1235             : }
    1236             : 
    1237             : // -----------------------------------------------------------------------------
    1238             : 
    1239           0 : sal_Bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uIntPtr nInsertPos )
    1240             : {
    1241           0 :     sal_Bool bRet = sal_False;
    1242             : 
    1243           0 :     if( rxTransferable.is() )
    1244             :     {
    1245           0 :         TransferableDataHelper  aDataHelper( rxTransferable );
    1246           0 :         Graphic*                pGraphic = NULL;
    1247             : 
    1248           0 :         if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
    1249             :         {
    1250           0 :             SotStorageStreamRef xModelStm;
    1251             : 
    1252           0 :             if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
    1253           0 :                 bRet = InsertModelStream( xModelStm, nInsertPos );
    1254             :         }
    1255           0 :         else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
    1256           0 :                  aDataHelper.HasFormat( FORMAT_FILE ) )
    1257             :         {
    1258           0 :             FileList aFileList;
    1259             : 
    1260           0 :             if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
    1261           0 :                 aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList );
    1262             :             else
    1263             :             {
    1264           0 :                 String aFile;
    1265             : 
    1266           0 :                 aDataHelper.GetString( FORMAT_FILE, aFile );
    1267             : 
    1268           0 :                 if( aFile.Len() )
    1269           0 :                     aFileList.AppendFile( aFile );
    1270             :             }
    1271             : 
    1272           0 :             for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
    1273             :             {
    1274           0 :                 const String    aFile( aFileList.GetFile( i ) );
    1275           0 :                 INetURLObject   aURL( aFile );
    1276             : 
    1277           0 :                 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
    1278             :                 {
    1279           0 :                     OUString aLocalURL;
    1280             : 
    1281           0 :                     if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) )
    1282           0 :                         aURL = INetURLObject( aLocalURL );
    1283             :                 }
    1284             : 
    1285           0 :                 if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
    1286           0 :                     bRet = InsertFileOrDirURL( aURL, nInsertPos );
    1287           0 :             }
    1288             :         }
    1289             :         else
    1290             :         {
    1291           0 :             Graphic aGraphic;
    1292           0 :             sal_uIntPtr nFormat = 0;
    1293             : 
    1294           0 :             if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
    1295           0 :                 nFormat = SOT_FORMATSTR_ID_SVXB;
    1296           0 :             else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
    1297           0 :                 nFormat = FORMAT_GDIMETAFILE;
    1298           0 :             else if( aDataHelper.HasFormat( FORMAT_BITMAP ) )
    1299           0 :                 nFormat = FORMAT_BITMAP;
    1300             : 
    1301           0 :             if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) )
    1302           0 :                 pGraphic = new Graphic( aGraphic );
    1303             :         }
    1304             : 
    1305           0 :         if( pGraphic )
    1306             :         {
    1307           0 :             bRet = sal_False;
    1308             : 
    1309           0 :             if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
    1310             :             {
    1311             : 
    1312           0 :                 ImageMap aImageMap;
    1313             : 
    1314             :                 // according to KA we don't need a BaseURL here
    1315           0 :                 if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) )
    1316             :                 {
    1317           0 :                     SvxGalleryDrawModel aModel;
    1318             : 
    1319           0 :                     if( aModel.GetModel() )
    1320             :                     {
    1321           0 :                         SgaUserDataFactory  aFactory;
    1322             : 
    1323           0 :                         SdrPage*    pPage = aModel.GetModel()->GetPage(0);
    1324           0 :                         SdrGrafObj* pGrafObj = new SdrGrafObj( *pGraphic );
    1325             : 
    1326           0 :                         pGrafObj->AppendUserData( new SgaIMapInfo( aImageMap ) );
    1327           0 :                         pPage->InsertObject( pGrafObj );
    1328           0 :                         bRet = InsertModel( *aModel.GetModel(), nInsertPos );
    1329           0 :                     }
    1330           0 :                 }
    1331             :             }
    1332             : 
    1333           0 :             if( !bRet )
    1334           0 :                 bRet = InsertGraphic( *pGraphic, nInsertPos );
    1335             : 
    1336           0 :             delete pGraphic;
    1337           0 :         }
    1338             :     }
    1339             : 
    1340           0 :     return bRet;
    1341             : }
    1342             : 
    1343             : // -----------------------------------------------------------------------------
    1344             : 
    1345           0 : void GalleryTheme::CopyToClipboard( Window* pWindow, sal_uIntPtr nPos )
    1346             : {
    1347           0 :     GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
    1348           0 :     pTransferable->CopyToClipboard( pWindow );
    1349           0 : }
    1350             : 
    1351             : // -----------------------------------------------------------------------------
    1352             : 
    1353           0 : void GalleryTheme::StartDrag( Window* pWindow, sal_uIntPtr nPos )
    1354             : {
    1355           0 :     GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
    1356           0 :     pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
    1357           0 : }
    1358             : 
    1359             : // -----------------------------------------------------------------------------
    1360             : 
    1361          22 : SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
    1362             : {
    1363          22 :     const INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
    1364          44 :     const INetURLObject aRelURL2( GetParent()->GetUserURL() );
    1365          44 :     INetURLObject       aNewURL, aTempURL;
    1366          22 :     sal_uInt32          nCount = GetObjectCount();
    1367             :     sal_Bool                bRel;
    1368             : 
    1369          22 :     rOStm << (sal_uInt16) 0x0004;
    1370          22 :     write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, GetRealName(), RTL_TEXTENCODING_UTF8);
    1371          22 :     rOStm << nCount << (sal_uInt16) osl_getThreadTextEncoding();
    1372             : 
    1373         525 :     for( sal_uInt32 i = 0; i < nCount; i++ )
    1374             :     {
    1375         503 :         const GalleryObject* pObj = ImplGetGalleryObject( i );
    1376         503 :         String               aPath;
    1377             : 
    1378         503 :         if( SGA_OBJ_SVDRAW == pObj->eObjKind )
    1379             :         {
    1380           0 :             aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
    1381           0 :             bRel = sal_False;
    1382             :         }
    1383             :         else
    1384             :         {
    1385         503 :             aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
    1386         503 :             bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) ));
    1387             : 
    1388         503 :             if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
    1389             :             {
    1390           0 :                 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
    1391           0 :                 aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
    1392             :             }
    1393             :             else
    1394             :             {
    1395         503 :                 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
    1396         503 :                 bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) ));
    1397             : 
    1398         503 :                 if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
    1399             :                 {
    1400           0 :                     aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
    1401           0 :                     aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
    1402             :                 }
    1403             :                 else
    1404         503 :                     aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
    1405             :             }
    1406             :         }
    1407             : 
    1408         503 :         if ( m_aDestDir.Len() > 0 )
    1409             :         {
    1410         503 :             if ( aPath.SearchAndReplace(m_aDestDir, String()) != STRING_NOTFOUND )
    1411         503 :                 bRel = m_bDestDirRelative;
    1412             :             else
    1413             :                 SAL_WARN( "svx", "failed to replace destdir of '"
    1414             :                           << m_aDestDir << "' in '" << aPath << "'");
    1415             :         }
    1416             : 
    1417         503 :         rOStm << bRel;
    1418         503 :         write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aPath, RTL_TEXTENCODING_UTF8);
    1419         503 :         rOStm << pObj->nOffset << (sal_uInt16) pObj->eObjKind;
    1420         503 :     }
    1421             : 
    1422             :     // neuerdings wird ein 512-Byte-Reservepuffer gechrieben;
    1423             :     // um diesen zu erkennen werden zwei sal_uIntPtr-Ids geschrieben
    1424          22 :     rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' );
    1425             : 
    1426          22 :     const long      nReservePos = rOStm.Tell();
    1427          22 :     VersionCompat*  pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 );
    1428             : 
    1429          22 :     rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2
    1430             : 
    1431          22 :     delete pCompat;
    1432             : 
    1433             :     // Rest des Puffers auffuellen
    1434          22 :     const long  nRest = std::max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L );
    1435             : 
    1436          22 :     if( nRest )
    1437             :     {
    1438          22 :         char* pReserve = new char[ nRest ];
    1439          22 :         memset( pReserve, 0, nRest );
    1440          22 :         rOStm.Write( pReserve, nRest );
    1441          22 :         delete[] pReserve;
    1442             :     }
    1443             : 
    1444          44 :     return rOStm;
    1445             : }
    1446             : 
    1447             : // ------------------------------------------------------------------------
    1448             : 
    1449          11 : SvStream& GalleryTheme::ReadData( SvStream& rIStm )
    1450             : {
    1451             :     sal_uInt32          nCount;
    1452             :     sal_uInt16          nVersion;
    1453          11 :     String              aThemeName;
    1454             :     rtl_TextEncoding    nTextEncoding;
    1455             : 
    1456          11 :     rIStm >> nVersion;
    1457          22 :     OString aTmpStr = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm);
    1458          11 :     rIStm >> nCount;
    1459             : 
    1460          11 :     if( nVersion >= 0x0004 )
    1461             :     {
    1462             :         sal_uInt16 nTmp16;
    1463          11 :         rIStm >> nTmp16;
    1464          11 :         nTextEncoding = (rtl_TextEncoding) nTmp16;
    1465             :     }
    1466             :     else
    1467           0 :         nTextEncoding = RTL_TEXTENCODING_UTF8;
    1468             : 
    1469          11 :     aThemeName = OStringToOUString(aTmpStr, nTextEncoding);
    1470             : 
    1471          11 :     if( nCount <= ( 1L << 14 ) )
    1472             :     {
    1473             :         GalleryObject*  pObj;
    1474          11 :         INetURLObject   aRelURL1( GetParent()->GetRelativeURL() );
    1475          22 :         INetURLObject   aRelURL2( GetParent()->GetUserURL() );
    1476             :         sal_uInt32      nId1, nId2;
    1477             :         sal_Bool            bRel;
    1478             : 
    1479          11 :         for( size_t i = 0, n = aObjectList.size(); i < n; ++i )
    1480             :         {
    1481           0 :             pObj = aObjectList[ i ];
    1482           0 :             Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
    1483           0 :             delete pObj;
    1484           0 :             Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
    1485             :         }
    1486          11 :         aObjectList.clear();
    1487             : 
    1488          11 :         for( sal_uInt32 i = 0; i < nCount; i++ )
    1489             :         {
    1490           0 :             pObj = new GalleryObject;
    1491             : 
    1492           0 :             String      aFileName;
    1493           0 :             String      aPath;
    1494             :             sal_uInt16  nTemp;
    1495             : 
    1496           0 :             rIStm >> bRel;
    1497           0 :             OString aTempFileName = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm);
    1498           0 :             rIStm >> pObj->nOffset;
    1499           0 :             rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp;
    1500             : 
    1501           0 :             aFileName = OStringToOUString(aTempFileName, osl_getThreadTextEncoding());
    1502             : 
    1503           0 :             if( bRel )
    1504             :             {
    1505           0 :                 aFileName.SearchAndReplaceAll( '\\', '/' );
    1506           0 :                 aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE );
    1507             : 
    1508           0 :                 if( aFileName.GetChar( 0 ) != '/' )
    1509           0 :                         aPath += '/';
    1510             : 
    1511           0 :                 aPath += aFileName;
    1512             : 
    1513           0 :                 pObj->aURL = INetURLObject( aPath );
    1514             : 
    1515           0 :                 if( !FileExists( pObj->aURL ) )
    1516             :                 {
    1517           0 :                     aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE );
    1518             : 
    1519           0 :                     if( aFileName.GetChar( 0 ) != '/' )
    1520           0 :                         aPath += '/';
    1521             : 
    1522           0 :                     aPath += aFileName;
    1523             : 
    1524             :                     // assign this URL, even in the case it is not valid (#94482)
    1525           0 :                     pObj->aURL = INetURLObject( aPath );
    1526             :                 }
    1527             :             }
    1528             :             else
    1529             :             {
    1530           0 :                 if( SGA_OBJ_SVDRAW == pObj->eObjKind )
    1531             :                 {
    1532           0 :                     const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) );
    1533             : 
    1534           0 :                     String aDummyURL( aBaseURLStr );
    1535           0 :                     pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE );
    1536             :                 }
    1537             :                 else
    1538             :                 {
    1539           0 :                     OUString aLocalURL;
    1540             : 
    1541           0 :                     pObj->aURL = INetURLObject( aFileName );
    1542             : 
    1543           0 :                     if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) &&
    1544           0 :                         ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) )
    1545             :                     {
    1546           0 :                         pObj->aURL = INetURLObject( aLocalURL );
    1547           0 :                     }
    1548             :                 }
    1549             :             }
    1550           0 :             aObjectList.push_back( pObj );
    1551           0 :         }
    1552             : 
    1553          11 :         rIStm >> nId1 >> nId2;
    1554             : 
    1555             :         // in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer;
    1556             :         // die Daten befinden sich am Anfang dieses Puffers und
    1557             :         // sind durch eine VersionCompat geklammert
    1558          33 :         if( !rIStm.IsEof() &&
    1559          22 :             nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
    1560          11 :             nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
    1561             :         {
    1562          11 :             VersionCompat*  pCompat = new VersionCompat( rIStm, STREAM_READ );
    1563             :             sal_uInt32      nTemp32;
    1564          11 :             sal_Bool            bThemeNameFromResource = sal_False;
    1565             : 
    1566          11 :             rIStm >> nTemp32;
    1567             : 
    1568          11 :             if( pCompat->GetVersion() >= 2 )
    1569             :             {
    1570          11 :                 rIStm >> bThemeNameFromResource;
    1571             :             }
    1572             : 
    1573          11 :             SetId( nTemp32, bThemeNameFromResource );
    1574          11 :             delete pCompat;
    1575          11 :         }
    1576             :     }
    1577             :     else
    1578           0 :         rIStm.SetError( SVSTREAM_READ_ERROR );
    1579             : 
    1580          11 :     ImplSetModified( sal_False );
    1581             : 
    1582          22 :     return rIStm;
    1583             : }
    1584             : 
    1585             : // ------------------------------------------------------------------------
    1586             : 
    1587          22 : SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme )
    1588             : {
    1589          22 :     return rTheme.WriteData( rOut );
    1590             : }
    1591             : 
    1592             : // ------------------------------------------------------------------------
    1593             : 
    1594          11 : SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme )
    1595             : {
    1596          11 :     return rTheme.ReadData( rIn );
    1597             : }
    1598             : 
    1599         536 : void GalleryTheme::ImplSetModified( sal_Bool bModified )
    1600         536 : { pThm->SetModified( bModified ); }
    1601             : 
    1602          22 : const OUString& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); }
    1603          44 : const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); }
    1604         503 : const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); }
    1605          22 : const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); }
    1606          22 : sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
    1607          11 : void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
    1608          22 : sal_Bool GalleryTheme::IsThemeNameFromResource() const { return pThm->IsNameFromResource(); }
    1609           0 : sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
    1610           0 : sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
    1611          22 : sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); }
    1612        1509 : const OUString& GalleryTheme::GetName() const { return pThm->GetThemeName(); }
    1613             : 
    1614           0 : void GalleryTheme::InsertAllThemes( ListBox& rListBox )
    1615             : {
    1616           0 :     for( sal_uInt16 i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ )
    1617           0 :         rListBox.InsertEntry(GAL_RESSTR(i));
    1618         258 : }
    1619             : 
    1620             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10