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