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::ReleaseObject( SgaObject* pObject ) 475 { 476 delete pObject; 477 } 478 479 // ------------------------------------------------------------------------ 480 481 sal_Bool GalleryTheme::RemoveObject( sal_uIntPtr nPos ) 482 { 483 GalleryObject* pEntry = aObjectList.Remove( nPos ); 484 485 if( !aObjectList.Count() ) 486 KillFile( GetSdgURL() ); 487 488 if( pEntry ) 489 { 490 if( SGA_OBJ_SVDRAW == pEntry->eObjKind ) 491 aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 492 493 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) ); 494 delete pEntry; 495 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) ); 496 497 ImplSetModified( sal_True ); 498 ImplBroadcast( nPos ); 499 } 500 501 return( pEntry != NULL ); 502 } 503 504 // ------------------------------------------------------------------------ 505 506 sal_Bool GalleryTheme::ChangeObjectPos( sal_uIntPtr nOldPos, sal_uIntPtr nNewPos ) 507 { 508 sal_Bool bRet = sal_False; 509 510 if( nOldPos != nNewPos ) 511 { 512 GalleryObject* pEntry = aObjectList.GetObject( nOldPos ); 513 514 if( pEntry ) 515 { 516 aObjectList.Insert( pEntry, nNewPos ); 517 518 if( nNewPos < nOldPos ) 519 nOldPos++; 520 521 aObjectList.Remove( nOldPos ); 522 ImplSetModified( bRet = sal_True ); 523 ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) ); 524 } 525 } 526 527 return bRet; 528 } 529 530 // ------------------------------------------------------------------------ 531 532 void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress ) 533 { 534 if( !IsReadOnly() && !IsImported() ) 535 { 536 Graphic aGraphic; 537 String aFormat; 538 GalleryObject* pEntry; 539 const sal_uIntPtr nCount = aObjectList.Count(); 540 sal_uIntPtr i; 541 542 LockBroadcaster(); 543 bAbortActualize = sal_False; 544 545 // LoeschFlag zuruecksetzen 546 for ( i = 0; i < nCount; i++ ) 547 aObjectList.GetObject( i )->bDummy = sal_False; 548 549 for( i = 0; ( i < nCount ) && !bAbortActualize; i++ ) 550 { 551 if( pProgress ) 552 pProgress->Update( i, nCount - 1 ); 553 554 pEntry = aObjectList.GetObject( i ); 555 556 const INetURLObject aURL( pEntry->aURL ); 557 558 rActualizeLink.Call( (void*) &aURL ); 559 560 // SvDraw-Objekte werden spaeter aktualisiert 561 if( pEntry->eObjKind != SGA_OBJ_SVDRAW ) 562 { 563 // Hier muss noch etwas eingebaut werden, 564 // das Files auf den ensprechenden Eintrag matched 565 // Grafiken als Grafik-Objekte in die Gallery aufnehmen 566 if( pEntry->eObjKind == SGA_OBJ_SOUND ) 567 { 568 SgaObjectSound aObjSound( aURL ); 569 if( !InsertObject( aObjSound ) ) 570 pEntry->bDummy = sal_True; 571 } 572 else 573 { 574 aGraphic.Clear(); 575 576 if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) ) 577 { 578 SgaObject* pNewObj; 579 580 if ( SGA_OBJ_INET == pEntry->eObjKind ) 581 pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat ); 582 else if ( aGraphic.IsAnimated() ) 583 pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat ); 584 else 585 pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat ); 586 587 if( !InsertObject( *pNewObj ) ) 588 pEntry->bDummy = sal_True; 589 590 delete pNewObj; 591 } 592 else 593 pEntry->bDummy = sal_True; // Loesch-Flag setzen 594 } 595 } 596 else 597 { 598 if ( aSvDrawStorageRef.Is() ) 599 { 600 const String aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) ); 601 SvStorageStreamRef pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ ); 602 603 if( pIStm && !pIStm->GetError() ) 604 { 605 pIStm->SetBufferSize( 16384 ); 606 607 SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL ); 608 609 if( !InsertObject( aNewObj ) ) 610 pEntry->bDummy = sal_True; 611 612 pIStm->SetBufferSize( 0L ); 613 } 614 } 615 } 616 } 617 618 // remove all entries with set flag 619 pEntry = aObjectList.First(); 620 while( pEntry ) 621 { 622 if( pEntry->bDummy ) 623 { 624 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) ); 625 delete aObjectList.Remove( pEntry ); 626 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) ); 627 628 pEntry = aObjectList.GetCurObject(); 629 } 630 else 631 pEntry = aObjectList.Next(); 632 } 633 634 // update theme 635 ::utl::TempFile aTmp; 636 INetURLObject aInURL( GetSdgURL() ); 637 INetURLObject aTmpURL( aTmp.GetURL() ); 638 639 DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 640 DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 641 642 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); 643 SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC ); 644 645 if( pIStm && pTmpStm ) 646 { 647 pEntry = aObjectList.First(); 648 649 while( pEntry ) 650 { 651 SgaObject* pObj; 652 653 switch( pEntry->eObjKind ) 654 { 655 case( SGA_OBJ_BMP ): pObj = new SgaObjectBmp(); break; 656 case( SGA_OBJ_ANIM ): pObj = new SgaObjectAnim(); break; 657 case( SGA_OBJ_INET ): pObj = new SgaObjectINet(); break; 658 case( SGA_OBJ_SVDRAW ): pObj = new SgaObjectSvDraw(); break; 659 case (SGA_OBJ_SOUND): pObj = new SgaObjectSound(); break; 660 661 default: 662 pObj = NULL; 663 break; 664 } 665 666 if( pObj ) 667 { 668 pIStm->Seek( pEntry->nOffset ); 669 *pIStm >> *pObj; 670 pEntry->nOffset = pTmpStm->Tell(); 671 *pTmpStm << *pObj; 672 delete pObj; 673 } 674 675 pEntry = aObjectList.Next(); 676 } 677 } 678 else 679 { 680 DBG_ERROR( "File(s) could not be opened" ); 681 } 682 683 delete pIStm; 684 delete pTmpStm; 685 686 CopyFile( aTmpURL, aInURL ); 687 KillFile( aTmpURL ); 688 689 sal_uIntPtr nStorErr = 0; 690 691 { 692 SvStorageRef aTempStorageRef( new SvStorage( sal_False, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) ); 693 aSvDrawStorageRef->CopyTo( aTempStorageRef ); 694 nStorErr = aSvDrawStorageRef->GetError(); 695 } 696 697 if( !nStorErr ) 698 { 699 aSvDrawStorageRef.Clear(); 700 CopyFile( aTmpURL, GetSdvURL() ); 701 ImplCreateSvDrawStorage(); 702 } 703 704 KillFile( aTmpURL ); 705 ImplSetModified( sal_True ); 706 ImplWrite(); 707 UnlockBroadcaster(); 708 } 709 } 710 711 // ------------------------------------------------------------------------ 712 713 GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sal_Bool bReadOnly ) 714 { 715 DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" ); 716 717 GalleryThemeEntry* pRet = NULL; 718 719 if( FileExists( rURL ) ) 720 { 721 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ ); 722 723 if( pIStm ) 724 { 725 String aThemeName; 726 sal_uInt32 nThemeId = 0; 727 sal_uInt16 nVersion; 728 sal_Bool bThemeNameFromResource = sal_False; 729 730 *pIStm >> nVersion; 731 732 if( nVersion <= 0x00ff ) 733 { 734 ByteString aTmpStr; 735 736 *pIStm >> aTmpStr; aThemeName = String( aTmpStr.GetBuffer(), RTL_TEXTENCODING_UTF8 ); 737 738 // Charakterkonvertierung durchfuehren 739 if( nVersion >= 0x0004 ) 740 { 741 sal_uInt32 nCount; 742 sal_uInt16 nTemp16; 743 744 *pIStm >> nCount >> nTemp16; 745 pIStm->Seek( STREAM_SEEK_TO_END ); 746 747 // pruefen, ob es sich um eine neuere Version handelt; 748 // daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen, 749 // falls dies ueberhaupt moeglich ist 750 if( pIStm->Tell() >= 520 ) 751 { 752 sal_uInt32 nId1, nId2; 753 754 pIStm->SeekRel( -520 ); 755 *pIStm >> nId1 >> nId2; 756 757 if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) && 758 nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) ) 759 { 760 VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ ); 761 762 *pIStm >> nThemeId; 763 764 if( pCompat->GetVersion() >= 2 ) 765 { 766 *pIStm >> bThemeNameFromResource; 767 } 768 769 delete pCompat; 770 } 771 } 772 } 773 774 INetURLObject aPathURL( rURL ); 775 776 aPathURL.removeSegment(); 777 aPathURL.removeFinalSlash(); 778 pRet = new GalleryThemeEntry( aPathURL, aThemeName, 779 String(rURL.GetBase()).Copy( 2, 6 ).ToInt32(), 780 bReadOnly, sal_False, sal_False, nThemeId, 781 bThemeNameFromResource ); 782 } 783 784 delete pIStm; 785 } 786 } 787 788 return pRet; 789 } 790 791 // ----------------------------------------------------------------------------- 792 793 sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, Bitmap& rBmp, sal_Bool ) 794 { 795 SgaObject* pObj = AcquireObject( nPos ); 796 sal_Bool bRet = sal_False; 797 798 if( pObj ) 799 { 800 rBmp = pObj->GetThumbBmp(); 801 ReleaseObject( pObj ); 802 bRet = sal_True; 803 } 804 805 return bRet; 806 } 807 808 // ----------------------------------------------------------------------------- 809 810 sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool bProgress ) 811 { 812 const GalleryObject* pObject = ImplGetGalleryObject( nPos ); 813 sal_Bool bRet = sal_False; 814 815 if( pObject ) 816 { 817 const INetURLObject aURL( ImplGetURL( pObject ) ); 818 819 switch( pObject->eObjKind ) 820 { 821 case( SGA_OBJ_BMP ): 822 case( SGA_OBJ_ANIM ): 823 case( SGA_OBJ_INET ): 824 { 825 String aFilterDummy; 826 bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE ); 827 } 828 break; 829 830 case( SGA_OBJ_SVDRAW ): 831 { 832 SvxGalleryDrawModel aModel; 833 834 if( aModel.GetModel() ) 835 { 836 if( GetModel( nPos, *aModel.GetModel(), bProgress ) ) 837 { 838 ImageMap aIMap; 839 840 if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) ) 841 bRet = sal_True; 842 else 843 { 844 VirtualDevice aVDev; 845 aVDev.SetMapMode( MapMode( MAP_100TH_MM ) ); 846 FmFormView aView( aModel.GetModel(), &aVDev ); 847 848 aView.hideMarkHandles(); 849 aView.ShowSdrPage(aView.GetModel()->GetPage(0)); 850 aView.MarkAll(); 851 rGraphic = aView.GetAllMarkedGraphic(); 852 bRet = sal_True; 853 } 854 } 855 } 856 } 857 break; 858 859 case( SGA_OBJ_SOUND ): 860 { 861 SgaObject* pObj = AcquireObject( nPos ); 862 863 if( pObj ) 864 { 865 Bitmap aBmp( pObj->GetThumbBmp() ); 866 aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE ); 867 rGraphic = aBmp; 868 ReleaseObject( pObj ); 869 bRet = sal_True; 870 } 871 } 872 break; 873 874 default: 875 break; 876 } 877 } 878 879 return bRet; 880 } 881 882 // ----------------------------------------------------------------------------- 883 884 sal_Bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_uIntPtr nInsertPos ) 885 { 886 sal_Bool bRet = sal_False; 887 888 if( rGraphic.GetType() != GRAPHIC_NONE ) 889 { 890 sal_uIntPtr nExportFormat = CVT_UNKNOWN; 891 const GfxLink aGfxLink( ( (Graphic&) rGraphic ).GetLink() ); 892 893 if( aGfxLink.GetDataSize() ) 894 { 895 switch( aGfxLink.GetType() ) 896 { 897 case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break; 898 case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break; 899 case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break; 900 case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break; 901 case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break; 902 case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break; 903 case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break; 904 case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break; 905 case( GFX_LINK_TYPE_NATIVE_SVG ): nExportFormat = CVT_SVG; break; 906 default: 907 break; 908 } 909 } 910 else 911 { 912 if( rGraphic.GetType() == GRAPHIC_BITMAP ) 913 { 914 if( rGraphic.IsAnimated() ) 915 nExportFormat = CVT_GIF; 916 else 917 nExportFormat = CVT_PNG; 918 } 919 else 920 nExportFormat = CVT_SVM; 921 } 922 923 const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) ); 924 SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC ); 925 926 if( pOStm ) 927 { 928 pOStm->SetVersion( SOFFICE_FILEFORMAT_50 ); 929 930 if( CVT_SVM == nExportFormat ) 931 { 932 GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() ); 933 934 aMtf.Write( *pOStm ); 935 bRet = ( pOStm->GetError() == ERRCODE_NONE ); 936 } 937 else 938 { 939 if( aGfxLink.GetDataSize() && aGfxLink.GetData() ) 940 { 941 pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() ); 942 bRet = ( pOStm->GetError() == ERRCODE_NONE ); 943 } 944 else 945 bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE ); 946 } 947 948 delete pOStm; 949 } 950 951 if( bRet ) 952 { 953 const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); 954 InsertObject( aObjBmp, nInsertPos ); 955 } 956 } 957 958 return bRet; 959 } 960 961 // ----------------------------------------------------------------------------- 962 963 sal_Bool GalleryTheme::GetModel( sal_uIntPtr nPos, SdrModel& rModel, sal_Bool ) 964 { 965 const GalleryObject* pObject = ImplGetGalleryObject( nPos ); 966 sal_Bool bRet = sal_False; 967 968 if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) ) 969 { 970 const INetURLObject aURL( ImplGetURL( pObject ) ); 971 SvStorageRef xStor( GetSvDrawStorage() ); 972 973 if( xStor.Is() ) 974 { 975 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) ); 976 SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) ); 977 978 if( xIStm.Is() && !xIStm->GetError() ) 979 { 980 xIStm->SetBufferSize( STREAMBUF_SIZE ); 981 bRet = GallerySvDrawImport( *xIStm, rModel ); 982 xIStm->SetBufferSize( 0L ); 983 } 984 } 985 } 986 987 return bRet; 988 } 989 990 // ----------------------------------------------------------------------------- 991 992 sal_Bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_uIntPtr nInsertPos ) 993 { 994 INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) ); 995 SvStorageRef xStor( GetSvDrawStorage() ); 996 sal_Bool bRet = sal_False; 997 998 if( xStor.Is() ) 999 { 1000 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) ); 1001 SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) ); 1002 1003 if( xOStm.Is() && !xOStm->GetError() ) 1004 { 1005 SvMemoryStream aMemStm( 65535, 65535 ); 1006 FmFormModel* pFormModel = (FmFormModel*) &rModel; 1007 1008 pFormModel->BurnInStyleSheetAttributes(); 1009 1010 { 1011 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) ); 1012 1013 if( xDocOut.is() ) 1014 SvxDrawingLayerExport( pFormModel, xDocOut ); 1015 } 1016 1017 aMemStm.Seek( 0 ); 1018 1019 xOStm->SetBufferSize( 16348 ); 1020 GalleryCodec aCodec( *xOStm ); 1021 aCodec.Write( aMemStm ); 1022 1023 if( !xOStm->GetError() ) 1024 { 1025 SgaObjectSvDraw aObjSvDraw( rModel, aURL ); 1026 bRet = InsertObject( aObjSvDraw, nInsertPos ); 1027 } 1028 1029 xOStm->SetBufferSize( 0L ); 1030 xOStm->Commit(); 1031 } 1032 } 1033 1034 return bRet; 1035 } 1036 1037 // ----------------------------------------------------------------------------- 1038 1039 sal_Bool GalleryTheme::GetModelStream( sal_uIntPtr nPos, SotStorageStreamRef& rxModelStream, sal_Bool ) 1040 { 1041 const GalleryObject* pObject = ImplGetGalleryObject( nPos ); 1042 sal_Bool bRet = sal_False; 1043 1044 if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) ) 1045 { 1046 const INetURLObject aURL( ImplGetURL( pObject ) ); 1047 SvStorageRef xStor( GetSvDrawStorage() ); 1048 1049 if( xStor.Is() ) 1050 { 1051 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) ); 1052 SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) ); 1053 1054 if( xIStm.Is() && !xIStm->GetError() ) 1055 { 1056 sal_uInt32 nVersion = 0; 1057 1058 xIStm->SetBufferSize( 16348 ); 1059 1060 if( GalleryCodec::IsCoded( *xIStm, nVersion ) ) 1061 { 1062 SvxGalleryDrawModel aModel; 1063 1064 if( aModel.GetModel() ) 1065 { 1066 if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) ) 1067 { 1068 aModel.GetModel()->BurnInStyleSheetAttributes(); 1069 1070 { 1071 uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) ); 1072 1073 if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) ) 1074 rxModelStream->Commit(); 1075 } 1076 } 1077 1078 bRet = ( rxModelStream->GetError() == ERRCODE_NONE ); 1079 } 1080 } 1081 1082 xIStm->SetBufferSize( 0 ); 1083 } 1084 } 1085 } 1086 1087 return bRet; 1088 } 1089 1090 // ----------------------------------------------------------------------------- 1091 1092 sal_Bool GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, sal_uIntPtr nInsertPos ) 1093 { 1094 INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) ); 1095 SvStorageRef xStor( GetSvDrawStorage() ); 1096 sal_Bool bRet = sal_False; 1097 1098 if( xStor.Is() ) 1099 { 1100 const String aStmName( GetSvDrawStreamNameFromURL( aURL ) ); 1101 SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) ); 1102 1103 if( xOStm.Is() && !xOStm->GetError() ) 1104 { 1105 GalleryCodec aCodec( *xOStm ); 1106 SvMemoryStream aMemStm( 65535, 65535 ); 1107 1108 xOStm->SetBufferSize( 16348 ); 1109 aCodec.Write( *rxModelStream ); 1110 1111 if( !xOStm->GetError() ) 1112 { 1113 xOStm->Seek( 0 ); 1114 SgaObjectSvDraw aObjSvDraw( *xOStm, aURL ); 1115 bRet = InsertObject( aObjSvDraw, nInsertPos ); 1116 } 1117 1118 xOStm->SetBufferSize( 0L ); 1119 xOStm->Commit(); 1120 } 1121 } 1122 1123 return bRet; 1124 } 1125 1126 // ----------------------------------------------------------------------------- 1127 1128 sal_Bool GalleryTheme::GetURL( sal_uIntPtr nPos, INetURLObject& rURL, sal_Bool ) 1129 { 1130 const GalleryObject* pObject = ImplGetGalleryObject( nPos ); 1131 sal_Bool bRet = sal_False; 1132 1133 if( pObject ) 1134 { 1135 rURL = INetURLObject( ImplGetURL( pObject ) ); 1136 bRet = sal_True; 1137 } 1138 1139 return bRet; 1140 } 1141 1142 // ----------------------------------------------------------------------------- 1143 1144 sal_Bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_uIntPtr nInsertPos ) 1145 { 1146 Graphic aGraphic; 1147 String aFormat; 1148 SgaObject* pNewObj = NULL; 1149 const sal_uInt16 nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat ); 1150 sal_Bool bRet = sal_False; 1151 1152 if( nImportRet != SGA_IMPORT_NONE ) 1153 { 1154 if ( SGA_IMPORT_INET == nImportRet ) 1155 pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat ); 1156 else if ( aGraphic.IsAnimated() ) 1157 pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat ); 1158 else 1159 pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat ); 1160 } 1161 else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) ) 1162 pNewObj = (SgaObject*) new SgaObjectSound( rURL ); 1163 1164 if( pNewObj && InsertObject( *pNewObj, nInsertPos ) ) 1165 bRet = sal_True; 1166 1167 delete pNewObj; 1168 1169 return bRet; 1170 } 1171 1172 // ----------------------------------------------------------------------------- 1173 1174 sal_Bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_uIntPtr nInsertPos ) 1175 { 1176 INetURLObject aURL; 1177 ::std::vector< INetURLObject > aURLVector; 1178 sal_Bool bRet = sal_False; 1179 1180 try 1181 { 1182 ::ucbhelper::Content aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() ); 1183 sal_Bool bFolder = false; 1184 1185 aCnt.getPropertyValue( OUString::createFromAscii( "IsFolder" ) ) >>= bFolder; 1186 1187 if( bFolder ) 1188 { 1189 uno::Sequence< OUString > aProps( 1 ); 1190 aProps.getArray()[ 0 ] = OUString::createFromAscii( "Url" ); 1191 uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) ); 1192 uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); 1193 if( xContentAccess.is() ) 1194 { 1195 while( xResultSet->next() ) 1196 { 1197 aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() ); 1198 aURLVector.push_back( aURL ); 1199 } 1200 } 1201 } 1202 else 1203 aURLVector.push_back( rFileOrDirURL ); 1204 } 1205 catch( const ucb::ContentCreationException& ) 1206 { 1207 } 1208 catch( const uno::RuntimeException& ) 1209 { 1210 } 1211 catch( const uno::Exception& ) 1212 { 1213 } 1214 1215 ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() ); 1216 1217 while( aIter != aEnd ) 1218 bRet = bRet || InsertURL( *aIter++, nInsertPos ); 1219 1220 return bRet; 1221 } 1222 1223 // ----------------------------------------------------------------------------- 1224 1225 sal_Bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uIntPtr nInsertPos ) 1226 { 1227 sal_Bool bRet = sal_False; 1228 1229 if( rxTransferable.is() ) 1230 { 1231 TransferableDataHelper aDataHelper( rxTransferable ); 1232 Graphic* pGraphic = NULL; 1233 1234 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) ) 1235 { 1236 SotStorageStreamRef xModelStm; 1237 1238 if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) ) 1239 bRet = InsertModelStream( xModelStm, nInsertPos ); 1240 } 1241 else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) || 1242 aDataHelper.HasFormat( FORMAT_FILE ) ) 1243 { 1244 FileList aFileList; 1245 1246 if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ) 1247 aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ); 1248 else 1249 { 1250 String aFile; 1251 1252 aDataHelper.GetString( FORMAT_FILE, aFile ); 1253 1254 if( aFile.Len() ) 1255 aFileList.AppendFile( aFile ); 1256 } 1257 1258 for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i ) 1259 { 1260 const String aFile( aFileList.GetFile( i ) ); 1261 INetURLObject aURL( aFile ); 1262 1263 if( aURL.GetProtocol() == INET_PROT_NOT_VALID ) 1264 { 1265 String aLocalURL; 1266 1267 if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) ) 1268 aURL = INetURLObject( aLocalURL ); 1269 } 1270 1271 if( aURL.GetProtocol() != INET_PROT_NOT_VALID ) 1272 bRet = InsertFileOrDirURL( aURL, nInsertPos ); 1273 } 1274 } 1275 else 1276 { 1277 Graphic aGraphic; 1278 sal_uIntPtr nFormat = 0; 1279 1280 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) ) 1281 nFormat = SOT_FORMATSTR_ID_SVXB; 1282 else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) ) 1283 nFormat = FORMAT_GDIMETAFILE; 1284 else if( aDataHelper.HasFormat( FORMAT_BITMAP ) ) 1285 nFormat = FORMAT_BITMAP; 1286 1287 if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) ) 1288 pGraphic = new Graphic( aGraphic ); 1289 } 1290 1291 if( pGraphic ) 1292 { 1293 bRet = sal_False; 1294 1295 if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) ) 1296 { 1297 1298 ImageMap aImageMap; 1299 1300 // according to KA we don't need a BaseURL here 1301 if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) ) 1302 { 1303 SvxGalleryDrawModel aModel; 1304 1305 if( aModel.GetModel() ) 1306 { 1307 SgaUserDataFactory aFactory; 1308 1309 SdrPage* pPage = aModel.GetModel()->GetPage(0); 1310 SdrGrafObj* pGrafObj = new SdrGrafObj( *pGraphic ); 1311 1312 pGrafObj->InsertUserData( new SgaIMapInfo( aImageMap ) ); 1313 pPage->InsertObject( pGrafObj ); 1314 bRet = InsertModel( *aModel.GetModel(), nInsertPos ); 1315 } 1316 } 1317 } 1318 1319 if( !bRet ) 1320 bRet = InsertGraphic( *pGraphic, nInsertPos ); 1321 1322 delete pGraphic; 1323 } 1324 } 1325 1326 return bRet; 1327 } 1328 1329 // ----------------------------------------------------------------------------- 1330 1331 void GalleryTheme::CopyToClipboard( Window* pWindow, sal_uIntPtr nPos ) 1332 { 1333 GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false ); 1334 pTransferable->CopyToClipboard( pWindow ); 1335 } 1336 1337 // ----------------------------------------------------------------------------- 1338 1339 void GalleryTheme::StartDrag( Window* pWindow, sal_uIntPtr nPos ) 1340 { 1341 GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true ); 1342 pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK ); 1343 } 1344 1345 // ----------------------------------------------------------------------------- 1346 1347 SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const 1348 { 1349 const INetURLObject aRelURL1( GetParent()->GetRelativeURL() ); 1350 const INetURLObject aRelURL2( GetParent()->GetUserURL() ); 1351 INetURLObject aNewURL, aTempURL; 1352 sal_uInt32 nCount = GetObjectCount(); 1353 sal_Bool bRel; 1354 1355 rOStm << (sal_uInt16) 0x0004; 1356 rOStm << ByteString( GetRealName(), RTL_TEXTENCODING_UTF8 ); 1357 rOStm << nCount << (sal_uInt16) gsl_getSystemTextEncoding(); 1358 1359 for( sal_uInt32 i = 0; i < nCount; i++ ) 1360 { 1361 const GalleryObject* pObj = ImplGetGalleryObject( i ); 1362 String aPath; 1363 1364 if( SGA_OBJ_SVDRAW == pObj->eObjKind ) 1365 { 1366 aPath = GetSvDrawStreamNameFromURL( pObj->aURL ); 1367 bRel = sal_False; 1368 } 1369 else 1370 { 1371 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ); 1372 bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) )); 1373 1374 if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) ) 1375 { 1376 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ); 1377 aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ); 1378 } 1379 else 1380 { 1381 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ); 1382 bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) )); 1383 1384 if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) ) 1385 { 1386 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ); 1387 aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ); 1388 } 1389 else 1390 aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ); 1391 } 1392 } 1393 1394 aPath.SearchAndReplace(m_aDestDir, String()); 1395 rOStm << bRel << ByteString( aPath, RTL_TEXTENCODING_UTF8 ) << pObj->nOffset << (sal_uInt16) pObj->eObjKind; 1396 } 1397 1398 // neuerdings wird ein 512-Byte-Reservepuffer gechrieben; 1399 // um diesen zu erkennen werden zwei sal_uIntPtr-Ids geschrieben 1400 rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' ); 1401 1402 const long nReservePos = rOStm.Tell(); 1403 VersionCompat* pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 ); 1404 1405 rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2 1406 1407 delete pCompat; 1408 1409 // Rest des Puffers auffuellen 1410 const long nRest = Max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L ); 1411 1412 if( nRest ) 1413 { 1414 char* pReserve = new char[ nRest ]; 1415 memset( pReserve, 0, nRest ); 1416 rOStm.Write( pReserve, nRest ); 1417 delete[] pReserve; 1418 } 1419 1420 return rOStm; 1421 } 1422 1423 // ------------------------------------------------------------------------ 1424 1425 SvStream& GalleryTheme::ReadData( SvStream& rIStm ) 1426 { 1427 sal_uInt32 nCount; 1428 sal_uInt16 nVersion; 1429 ByteString aTmpStr; 1430 String aThemeName; 1431 rtl_TextEncoding nTextEncoding; 1432 1433 aImportName = String(); 1434 rIStm >> nVersion >> aTmpStr >> nCount; 1435 1436 if( nVersion >= 0x0004 ) 1437 { 1438 sal_uInt16 nTmp16; 1439 rIStm >> nTmp16; 1440 nTextEncoding = (rtl_TextEncoding) nTmp16; 1441 } 1442 else 1443 nTextEncoding = RTL_TEXTENCODING_UTF8; 1444 1445 aThemeName = String( aTmpStr.GetBuffer(), nTextEncoding ); 1446 1447 if( nCount <= ( 1L << 14 ) ) 1448 { 1449 GalleryObject* pObj; 1450 INetURLObject aRelURL1( GetParent()->GetRelativeURL() ); 1451 INetURLObject aRelURL2( GetParent()->GetUserURL() ); 1452 sal_uInt32 nId1, nId2; 1453 sal_Bool bRel; 1454 1455 for( pObj = aObjectList.First(); pObj; pObj = aObjectList.Next() ) 1456 { 1457 Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) ); 1458 delete pObj; 1459 Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) ); 1460 } 1461 1462 aObjectList.Clear(); 1463 1464 for( sal_uInt32 i = 0; i < nCount; i++ ) 1465 { 1466 pObj = new GalleryObject; 1467 1468 ByteString aTempFileName; 1469 String aFileName; 1470 String aPath; 1471 sal_uInt16 nTemp; 1472 1473 rIStm >> bRel >> aTempFileName >> pObj->nOffset; 1474 rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp; 1475 1476 aFileName = String( aTempFileName.GetBuffer(), gsl_getSystemTextEncoding() ); 1477 1478 if( bRel ) 1479 { 1480 aFileName.SearchAndReplaceAll( '\\', '/' ); 1481 aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE ); 1482 1483 if( aFileName.GetChar( 0 ) != '/' ) 1484 aPath += '/'; 1485 1486 aPath += aFileName; 1487 1488 pObj->aURL = INetURLObject( aPath ); 1489 1490 if( !FileExists( pObj->aURL ) ) 1491 { 1492 aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE ); 1493 1494 if( aFileName.GetChar( 0 ) != '/' ) 1495 aPath += '/'; 1496 1497 aPath += aFileName; 1498 1499 // assign this URL, even in the case it is not valid (#94482) 1500 pObj->aURL = INetURLObject( aPath ); 1501 } 1502 } 1503 else 1504 { 1505 if( SGA_OBJ_SVDRAW == pObj->eObjKind ) 1506 { 1507 const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) ); 1508 1509 String aDummyURL( aBaseURLStr ); 1510 pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE ); 1511 } 1512 else 1513 { 1514 String aLocalURL; 1515 1516 pObj->aURL = INetURLObject( aFileName ); 1517 1518 if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) && 1519 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) ) 1520 { 1521 pObj->aURL = INetURLObject( aLocalURL ); 1522 } 1523 } 1524 } 1525 1526 aObjectList.Insert( pObj, LIST_APPEND ); 1527 } 1528 1529 rIStm >> nId1 >> nId2; 1530 1531 // in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer; 1532 // die Daten befinden sich am Anfang dieses Puffers und 1533 // sind durch eine VersionCompat geklammert 1534 if( !rIStm.IsEof() && 1535 nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) && 1536 nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) ) 1537 { 1538 VersionCompat* pCompat = new VersionCompat( rIStm, STREAM_READ ); 1539 sal_uInt32 nTemp32; 1540 sal_Bool bThemeNameFromResource = sal_False; 1541 1542 rIStm >> nTemp32; 1543 1544 if( pCompat->GetVersion() >= 2 ) 1545 { 1546 rIStm >> bThemeNameFromResource; 1547 } 1548 1549 SetId( nTemp32, bThemeNameFromResource ); 1550 delete pCompat; 1551 } 1552 } 1553 else 1554 rIStm.SetError( SVSTREAM_READ_ERROR ); 1555 1556 ImplSetModified( sal_False ); 1557 1558 return rIStm; 1559 } 1560 1561 // ------------------------------------------------------------------------ 1562 1563 SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme ) 1564 { 1565 return rTheme.WriteData( rOut ); 1566 } 1567 1568 // ------------------------------------------------------------------------ 1569 1570 SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme ) 1571 { 1572 return rTheme.ReadData( rIn ); 1573 } 1574 1575 void GalleryTheme::ImplSetModified( sal_Bool bModified ) 1576 { pThm->SetModified( bModified ); } 1577 1578 const String& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); } 1579 const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); } 1580 const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); } 1581 const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); } 1582 sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); } 1583 void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); } 1584 sal_Bool GalleryTheme::IsThemeNameFromResource() const { return pThm->IsNameFromResource(); } 1585 sal_Bool GalleryTheme::IsImported() const { return pThm->IsImported(); } 1586 sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); } 1587 sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); } 1588 sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); } 1589 const String& GalleryTheme::GetName() const { return IsImported() ? aImportName : pThm->GetThemeName(); } 1590 1591 void GalleryTheme::InsertAllThemes( ListBox& rListBox ) 1592 { 1593 for( sal_uInt16 i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ ) 1594 rListBox.InsertEntry( String( GAL_RESID( i ) ) ); 1595 } 1596 1597