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