LibreOffice Module svx (master)  1
galtheme.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <sal/config.h>
23 #include <sal/log.hxx>
24 
25 #include <algorithm>
26 
27 #include <comphelper/fileformat.h>
29 #include <osl/file.hxx>
30 #include <osl/thread.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <tools/urlobj.hxx>
33 #include <tools/vcompat.hxx>
34 #include <unotools/streamwrap.hxx>
36 #include <unotools/tempfile.hxx>
37 #include <ucbhelper/content.hxx>
38 #include <com/sun/star/ucb/ContentCreationException.hpp>
39 #include <sot/storage.hxx>
40 #include <sot/formats.hxx>
41 #include <sot/filelist.hxx>
42 #include <vcl/virdev.hxx>
43 #include <vcl/cvtgrf.hxx>
44 #include <avmedia/mediawindow.hxx>
45 #include <svx/svdograf.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 <svx/svdpage.hxx>
53 #include <com/sun/star/sdbc/XResultSet.hpp>
54 #include <com/sun/star/ucb/XContentAccess.hpp>
55 #include <galobj.hxx>
56 #include <svx/gallery1.hxx>
57 #include "gallerydrawmodel.hxx"
58 #include <memory>
59 
60 using namespace ::com::sun::star;
61 
62 
64  : m_bDestDirRelative(false)
65  , pParent(pGallery)
66  , pThm(pThemeEntry)
67  , mnThemeLockCount(0)
68  , mnBroadcasterLockCount(0)
69  , nDragPos(0)
70  , bDragging(false)
71  , bAbortActualize(false)
72 {
74 }
75 
77 {
78  ImplWrite();
79 
80  for (auto & pEntry : aObjectList)
81  {
83  pEntry.reset();
84  }
85  aObjectList.clear();
86 
87 }
88 
90 {
91  try
92  {
93  aSvDrawStorageRef = new SotStorage( false, GetSdvURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), pThm->IsReadOnly() ? StreamMode::READ : StreamMode::STD_READWRITE );
94  // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
95  if ( ( aSvDrawStorageRef->GetError() != ERRCODE_NONE ) && !pThm->IsReadOnly() )
97  }
98  catch (const css::ucb::ContentCreationException&)
99  {
100  TOOLS_WARN_EXCEPTION("svx", "failed to open: "
102  << "due to");
103  }
104 }
105 
106 bool GalleryTheme::ImplWriteSgaObject(const SgaObject& rObj, sal_uInt32 nPos, GalleryObject* pExistentEntry)
107 {
108  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE ));
109  bool bRet = false;
110 
111  if( pOStm )
112  {
113  const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END );
114 
115  rObj.WriteData( *pOStm, m_aDestDir );
116 
117  if( !pOStm->GetError() )
118  {
119  GalleryObject* pEntry;
120 
121  if( !pExistentEntry )
122  {
123  pEntry = new GalleryObject;
124  if ( nPos < aObjectList.size() )
125  {
126  aObjectList.emplace( aObjectList.begin() + nPos, pEntry );
127  }
128  else
129  aObjectList.emplace_back( pEntry );
130  }
131  else
132  pEntry = pExistentEntry;
133 
134  pEntry->aURL = rObj.GetURL();
135  pEntry->nOffset = nOffset;
136  pEntry->eObjKind = rObj.GetObjKind();
137  bRet = true;
138  }
139  }
140 
141  return bRet;
142 }
143 
144 std::unique_ptr<SgaObject> GalleryTheme::ImplReadSgaObject( GalleryObject const * pEntry )
145 {
146  std::unique_ptr<SgaObject> pSgaObj;
147 
148  if( pEntry )
149  {
150  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
151 
152  if( pIStm )
153  {
154  sal_uInt32 nInventor;
155 
156  // Check to ensure that the file is a valid SGA file
157  pIStm->Seek( pEntry->nOffset );
158  pIStm->ReadUInt32( nInventor );
159 
160  if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
161  {
162  pIStm->Seek( pEntry->nOffset );
163 
164  switch( pEntry->eObjKind )
165  {
166  case SgaObjKind::Bitmap: pSgaObj.reset(new SgaObjectBmp()); break;
167  case SgaObjKind::Animation: pSgaObj.reset(new SgaObjectAnim()); break;
168  case SgaObjKind::Inet: pSgaObj.reset(new SgaObjectINet()); break;
169  case SgaObjKind::SvDraw: pSgaObj.reset(new SgaObjectSvDraw()); break;
170  case SgaObjKind::Sound: pSgaObj.reset(new SgaObjectSound()); break;
171 
172  default:
173  break;
174  }
175 
176  if( pSgaObj )
177  {
178  ReadSgaObject( *pIStm, *pSgaObj );
179  pSgaObj->ImplUpdateURL( pEntry->aURL );
180  }
181  }
182  }
183  }
184 
185  return pSgaObj;
186 }
187 
189 {
190  if( pThm->IsModified() )
191  {
192  INetURLObject aPathURL( GetThmURL() );
193 
194  aPathURL.removeSegment();
195  aPathURL.removeFinalSlash();
196 
197  DBG_ASSERT( aPathURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
198 
199  if( FileExists( aPathURL ) || CreateDir( aPathURL ) )
200  {
201 #ifdef UNX
202  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::COPY_ON_SYMLINK | StreamMode::TRUNC ));
203 #else
204  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ));
205 #endif
206 
207  if( pOStm )
208  {
209  WriteGalleryTheme( *pOStm, *this );
210  pOStm.reset();
211  }
212 
213  ImplSetModified( false );
214  }
215  }
216 }
217 
219 {
220  for (auto const & i : aObjectList)
221  if ( i->aURL == rURL )
222  return i.get();
223  return nullptr;
224 }
225 
227 {
229 
230  if( pObject )
231  aURL = pObject->aURL;
232 
233  return aURL;
234 }
235 
237 {
238  INetURLObject aDir( GetParent()->GetUserURL() );
239  INetURLObject aInfoFileURL( GetParent()->GetUserURL() );
240  INetURLObject aNewURL;
241  sal_uInt32 nNextNumber = 1999;
242  char const* pExt = nullptr;
243  bool bExists;
244 
245  aDir.Append( "dragdrop" );
246  CreateDir( aDir );
247 
248  aInfoFileURL.Append( "sdddndx1" );
249 
250  // read next possible number
251  if( FileExists( aInfoFileURL ) )
252  {
253  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
254 
255  if( pIStm )
256  {
257  pIStm->ReadUInt32( nNextNumber );
258  }
259  }
260 
261  // create extension
262  if( nFormat != ConvertDataFormat::Unknown )
263  {
264  switch( nFormat )
265  {
266  case ConvertDataFormat::BMP: pExt = ".bmp"; break;
267  case ConvertDataFormat::GIF: pExt = ".gif"; break;
268  case ConvertDataFormat::JPG: pExt = ".jpg"; break;
269  case ConvertDataFormat::MET: pExt = ".met"; break;
270  case ConvertDataFormat::PCT: pExt = ".pct"; break;
271  case ConvertDataFormat::PNG: pExt = ".png"; break;
272  case ConvertDataFormat::SVM: pExt = ".svm"; break;
273  case ConvertDataFormat::TIF: pExt = ".tif"; break;
274  case ConvertDataFormat::WMF: pExt = ".wmf"; break;
275  case ConvertDataFormat::EMF: pExt = ".emf"; break;
276 
277  default:
278  pExt = ".grf";
279  break;
280  }
281  }
282 
283  do
284  {
285  // get URL
286  if( SgaObjKind::SvDraw == eObjKind )
287  {
288  OUString aFileName( "gallery/svdraw/dd" );
289  aNewURL = INetURLObject( aFileName += OUString::number( ++nNextNumber % 99999999 ), INetProtocol::PrivSoffice );
290 
291  bExists = false;
292 
293  for (auto const & p : aObjectList)
294  if ( p->aURL == aNewURL )
295  {
296  bExists = true;
297  break;
298  }
299  }
300  else
301  {
302  OUString aFileName = "dd" + OUString::number( ++nNextNumber % 999999 );
303 
304  if (pExt)
305  aFileName += OUString( pExt, strlen(pExt), RTL_TEXTENCODING_ASCII_US );
306 
307  aNewURL = aDir;
308  aNewURL.Append( aFileName );
309 
310  bExists = FileExists( aNewURL );
311  }
312  }
313  while( bExists );
314 
315  // write updated number
316  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE ));
317 
318  if( pOStm )
319  {
320  pOStm->WriteUInt32( nNextNumber );
321  }
322 
323  return aNewURL;
324 }
325 
326 void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos)
327 {
328  if( !IsBroadcasterLocked() )
329  {
330  if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
331  nUpdatePos = GetObjectCount() - 1;
332 
333  Broadcast( GalleryHint( GalleryHintType::THEME_UPDATEVIEW, GetName(), reinterpret_cast<void*>(nUpdatePos) ) );
334  }
335 }
336 
338 {
339  DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
340 
341  bool bRet = false;
342 
343  if( mnThemeLockCount )
344  {
346  bRet = true;
347  }
348 
349  return bRet;
350 }
351 
353 {
354  DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
355 
357  ImplBroadcast( 0 );
358 }
359 
360 bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
361 {
362  if (!rObj.IsValid())
363  return false;
364 
365  GalleryObject* pFoundEntry = nullptr;
366  sal_uInt32 iFoundPos = 0;
367  for (sal_uInt32 n = aObjectList.size(); iFoundPos < n; ++iFoundPos)
368  {
369  if (aObjectList[ iFoundPos ]->aURL == rObj.GetURL())
370  {
371  pFoundEntry = aObjectList[ iFoundPos ].get();
372  break;
373  }
374  }
375 
376  if (pFoundEntry)
377  {
378  GalleryObject aNewEntry;
379 
380  // update title of new object if necessary
381  if (rObj.GetTitle().isEmpty())
382  {
383  std::unique_ptr<SgaObject> pOldObj(ImplReadSgaObject(pFoundEntry));
384 
385  if (pOldObj)
386  {
387  const_cast<SgaObject&>(rObj).SetTitle( pOldObj->GetTitle() );
388  }
389  }
390  else if (rObj.GetTitle() == "__<empty>__")
391  const_cast<SgaObject&>(rObj).SetTitle("");
392 
393  ImplWriteSgaObject(rObj, nInsertPos, &aNewEntry);
394  pFoundEntry->nOffset = aNewEntry.nOffset;
395  }
396  else
397  ImplWriteSgaObject(rObj, nInsertPos, nullptr);
398 
399  ImplSetModified(true);
400  ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos);
401 
402  return true;
403 }
404 
405 std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
406 {
408 }
409 
410 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath) const
411 {
412  const GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
413 
414  rBitmapEx = pGalleryObject->maPreviewBitmapEx;
415  rSize = pGalleryObject->maPreparedSize;
416  rTitle = pGalleryObject->maTitle;
417  rPath = pGalleryObject->maPath;
418 }
419 
420 void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath)
421 {
422  GalleryObject* pGalleryObject = aObjectList[ nPos ].get();
423 
424  pGalleryObject->maPreviewBitmapEx = rBitmapEx;
425  pGalleryObject->maPreparedSize = rSize;
426  pGalleryObject->maTitle = rTitle;
427  pGalleryObject->maPath = rPath;
428 }
429 
430 void GalleryTheme::RemoveObject(sal_uInt32 nPos)
431 {
432  auto it = aObjectList.begin() + nPos;
433  std::unique_ptr<GalleryObject> pEntry = std::move(*it);
434  aObjectList.erase( it );
435 
436  if( aObjectList.empty() )
437  KillFile( GetSdgURL() );
438 
439  if( SgaObjKind::SvDraw == pEntry->eObjKind )
440  aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
441 
443  pEntry.reset();
444 
445  ImplSetModified( true );
446  ImplBroadcast( nPos );
447 }
448 
449 bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
450 {
451  if (nOldPos == nNewPos || nOldPos >= aObjectList.size())
452  return false;
453 
454  std::unique_ptr<GalleryObject> pEntry = std::move(aObjectList[nOldPos]);
455 
456  aObjectList.insert(aObjectList.begin() + nNewPos, std::move(pEntry));
457 
458  if (nNewPos < nOldPos)
459  nOldPos++;
460 
461  auto it = aObjectList.begin() + nOldPos;
462  aObjectList.erase(it);
463 
464  ImplSetModified(true);
465  ImplBroadcast((nNewPos < nOldPos)? nNewPos: (nNewPos - 1));
466 
467  return true;
468 }
469 
471 {
472  if( IsReadOnly() )
473  return;
474 
475  Graphic aGraphic;
476  OUString aFormat;
477  const sal_uInt32 nCount = aObjectList.size();
478 
479  LockBroadcaster();
480  bAbortActualize = false;
481 
482  // reset delete flag
483  for (sal_uInt32 i = 0; i < nCount; i++)
484  aObjectList[ i ]->mbDelete = false;
485 
486  for (sal_uInt32 i = 0; ( i < nCount ) && !bAbortActualize; i++)
487  {
488  if( pProgress )
489  pProgress->Update( i, nCount - 1 );
490 
491  GalleryObject* pEntry = aObjectList[ i ].get();
492 
493  const INetURLObject aURL( pEntry->aURL );
494 
495  rActualizeLink.Call( aURL );
496 
497  // SvDraw objects will be updated later
498  if( pEntry->eObjKind != SgaObjKind::SvDraw )
499  {
500  // Still a function should be implemented,
501  // which assigns files to the relevant entry.
502  // insert graphics as graphic objects into the gallery
503  if( pEntry->eObjKind == SgaObjKind::Sound )
504  {
505  SgaObjectSound aObjSound( aURL );
506  if( !InsertObject( aObjSound ) )
507  pEntry->mbDelete = true;
508  }
509  else
510  {
511  aGraphic.Clear();
512 
513  if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) != GalleryGraphicImportRet::IMPORT_NONE )
514  {
515  std::unique_ptr<SgaObject> pNewObj;
516 
517  if ( SgaObjKind::Inet == pEntry->eObjKind )
518  pNewObj.reset(new SgaObjectINet( aGraphic, aURL ));
519  else if ( aGraphic.IsAnimated() )
520  pNewObj.reset(new SgaObjectAnim( aGraphic, aURL ));
521  else
522  pNewObj.reset(new SgaObjectBmp( aGraphic, aURL ));
523 
524  if( !InsertObject( *pNewObj ) )
525  pEntry->mbDelete = true;
526  }
527  else
528  pEntry->mbDelete = true; // set delete flag
529  }
530  }
531  else
532  {
533  if ( aSvDrawStorageRef.is() )
534  {
535  const OUString aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
536  tools::SvRef<SotStorageStream> pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, StreamMode::READ );
537 
538  if( pIStm.is() && !pIStm->GetError() )
539  {
540  pIStm->SetBufferSize( 16384 );
541 
542  SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
543 
544  if( !InsertObject( aNewObj ) )
545  pEntry->mbDelete = true;
546 
547  pIStm->SetBufferSize( 0 );
548  }
549  }
550  }
551  }
552 
553  // remove all entries with set flag
554  for ( auto it = aObjectList.begin(); it != aObjectList.end(); /* increment is in the body of loop */)
555  {
556  if( (*it)->mbDelete )
557  {
559  it = aObjectList.erase( it );
560  }
561  else
562  ++it;
563  }
564 
565  // update theme
566  ::utl::TempFile aTmp;
567  INetURLObject aInURL( GetSdgURL() );
568  INetURLObject aTmpURL( aTmp.GetURL() );
569 
570  DBG_ASSERT( aInURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
571  DBG_ASSERT( aTmpURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
572 
573  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
574  std::unique_ptr<SvStream> pTmpStm(::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ));
575 
576  if( pIStm && pTmpStm )
577  {
578  for (const auto & i : aObjectList)
579  {
580  GalleryObject* pEntry = i.get();
581  std::unique_ptr<SgaObject> pObj;
582 
583  switch( pEntry->eObjKind )
584  {
585  case SgaObjKind::Bitmap: pObj.reset(new SgaObjectBmp()); break;
586  case SgaObjKind::Animation: pObj.reset(new SgaObjectAnim()); break;
587  case SgaObjKind::Inet: pObj.reset(new SgaObjectINet()); break;
588  case SgaObjKind::SvDraw: pObj.reset(new SgaObjectSvDraw()); break;
589  case SgaObjKind::Sound: pObj.reset(new SgaObjectSound()); break;
590 
591  default:
592  break;
593  }
594 
595  if( pObj )
596  {
597  pIStm->Seek( pEntry->nOffset );
598  ReadSgaObject( *pIStm, *pObj);
599  pEntry->nOffset = pTmpStm->Tell();
600  WriteSgaObject( *pTmpStm, *pObj );
601  }
602  }
603  }
604  else
605  {
606  OSL_FAIL( "File(s) could not be opened" );
607  }
608 
609  pIStm.reset();
610  pTmpStm.reset();
611 
612  CopyFile( aTmpURL, aInURL );
613  KillFile( aTmpURL );
614 
615  ErrCode nStorErr = ERRCODE_NONE;
616 
617  try
618  {
619  tools::SvRef<SotStorage> aTempStorageRef( new SotStorage( false, aTmpURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::STD_READWRITE ) );
620  aSvDrawStorageRef->CopyTo( aTempStorageRef.get() );
621  nStorErr = aSvDrawStorageRef->GetError();
622  }
623  catch (const css::ucb::ContentCreationException&)
624  {
625  TOOLS_WARN_EXCEPTION("svx", "failed to open: "
626  << aTmpURL.GetMainURL(INetURLObject::DecodeMechanism::NONE)
627  << "due to");
628  nStorErr = ERRCODE_IO_GENERAL;
629  }
630 
631  if( nStorErr == ERRCODE_NONE )
632  {
634  CopyFile( aTmpURL, GetSdvURL() );
636  }
637 
638  KillFile( aTmpURL );
639  ImplSetModified( true );
640  ImplWrite();
642 }
643 
645 {
646  DBG_ASSERT( rURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
647 
648  GalleryThemeEntry* pRet = nullptr;
649 
650  if( FileExists( rURL ) )
651  {
652  std::unique_ptr<SvStream> pIStm(::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::READ ));
653 
654  if( pIStm )
655  {
656  OUString aThemeName;
657  sal_uInt16 nVersion;
658 
659  pIStm->ReadUInt16( nVersion );
660 
661  if( nVersion <= 0x00ff )
662  {
663  bool bThemeNameFromResource = false;
664  sal_uInt32 nThemeId = 0;
665 
666  OString aTmpStr = read_uInt16_lenPrefixed_uInt8s_ToOString(*pIStm);
667  aThemeName = OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8);
668 
669  // execute a character conversion
670  if( nVersion >= 0x0004 )
671  {
672  sal_uInt32 nCount;
673  sal_uInt16 nTemp16;
674 
675  pIStm->ReadUInt32( nCount ).ReadUInt16( nTemp16 );
676  pIStm->Seek( STREAM_SEEK_TO_END );
677 
678  // check whether there is a newer version;
679  // therefore jump back by 520Bytes (8 bytes ID + 512Bytes reserve buffer)
680  // if this is at all possible.
681  if( pIStm->Tell() >= 520 )
682  {
683  sal_uInt32 nId1, nId2;
684 
685  pIStm->SeekRel( -520 );
686  pIStm->ReadUInt32( nId1 ).ReadUInt32( nId2 );
687 
688  if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
689  nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
690  {
691  VersionCompat aCompat( *pIStm, StreamMode::READ );
692 
693  pIStm->ReadUInt32( nThemeId );
694 
695  if( aCompat.GetVersion() >= 2 )
696  {
697  pIStm->ReadCharAsBool( bThemeNameFromResource );
698  }
699  }
700  }
701  }
702 
703  pRet = new GalleryThemeEntry( false, rURL, aThemeName,
704  bReadOnly, false, nThemeId,
705  bThemeNameFromResource );
706  }
707  }
708  }
709 
710  return pRet;
711 }
712 
713 bool GalleryTheme::GetThumb(sal_uInt32 nPos, BitmapEx& rBmp)
714 {
715  std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
716  bool bRet = false;
717 
718  if( pObj )
719  {
720  rBmp = pObj->GetThumbBmp();
721  bRet = true;
722  }
723 
724  return bRet;
725 }
726 
727 bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
728 {
729  const GalleryObject* pObject = ImplGetGalleryObject( nPos );
730  bool bRet = false;
731 
732  if( pObject )
733  {
734  const INetURLObject aURL( ImplGetURL( pObject ) );
735 
736  switch( pObject->eObjKind )
737  {
738  case SgaObjKind::Bitmap:
740  case SgaObjKind::Inet:
741  {
742  OUString aFilterDummy;
743  bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy ) != GalleryGraphicImportRet::IMPORT_NONE );
744  }
745  break;
746 
747  case SgaObjKind::SvDraw:
748  {
749  SvxGalleryDrawModel aModel;
750 
751  if( aModel.GetModel() )
752  {
753  if( GetModel( nPos, *aModel.GetModel() ) )
754  {
755  ImageMap aIMap;
756 
757  if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
758  bRet = true;
759  else
760  {
762  pVDev->SetMapMode( MapMode( MapUnit::Map100thMM ) );
763  FmFormView aView(*aModel.GetModel(), pVDev);
764 
765  aView.hideMarkHandles();
766  aView.ShowSdrPage(aView.GetModel()->GetPage(0));
767  aView.MarkAll();
768  rGraphic = aView.GetAllMarkedGraphic();
769  bRet = true;
770  }
771  }
772  }
773  }
774  break;
775 
776  case SgaObjKind::Sound:
777  {
778  std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
779 
780  if( pObj )
781  {
782  rGraphic = pObj->GetThumbBmp();
783  //Bitmap aBmp( pObj->GetThumbBmp() );
784  //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
785  //rGraphic = aBmp;
786  bRet = true;
787  }
788  }
789  break;
790 
791  default:
792  break;
793  }
794  }
795 
796  return bRet;
797 }
798 
799 bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos)
800 {
801  bool bRet = false;
802 
803  if( rGraphic.GetType() != GraphicType::NONE )
804  {
805  ConvertDataFormat nExportFormat = ConvertDataFormat::Unknown;
806  const GfxLink aGfxLink( rGraphic.GetGfxLink() );
807 
808  if( aGfxLink.GetDataSize() )
809  {
810  switch( aGfxLink.GetType() )
811  {
812  case GfxLinkType::EpsBuffer: nExportFormat = ConvertDataFormat::SVM; break;
813  case GfxLinkType::NativeGif: nExportFormat = ConvertDataFormat::GIF; break;
814 
815  // #i15508# added BMP type
816  // could not find/trigger a call to this, but should do no harm
817  case GfxLinkType::NativeBmp: nExportFormat = ConvertDataFormat::BMP; break;
818 
819  case GfxLinkType::NativeJpg: nExportFormat = ConvertDataFormat::JPG; break;
820  case GfxLinkType::NativePng: nExportFormat = ConvertDataFormat::PNG; break;
821  case GfxLinkType::NativeTif: nExportFormat = ConvertDataFormat::TIF; break;
822  case GfxLinkType::NativeWmf: nExportFormat = ConvertDataFormat::WMF; break;
823  case GfxLinkType::NativeMet: nExportFormat = ConvertDataFormat::MET; break;
824  case GfxLinkType::NativePct: nExportFormat = ConvertDataFormat::PCT; break;
825  case GfxLinkType::NativeSvg: nExportFormat = ConvertDataFormat::SVG; break;
826  default:
827  break;
828  }
829  }
830  else
831  {
832  if( rGraphic.GetType() == GraphicType::Bitmap )
833  {
834  if( rGraphic.IsAnimated() )
835  nExportFormat = ConvertDataFormat::GIF;
836  else
837  nExportFormat = ConvertDataFormat::PNG;
838  }
839  else
840  nExportFormat = ConvertDataFormat::SVM;
841  }
842 
843  const INetURLObject aURL( ImplCreateUniqueURL( SgaObjKind::Bitmap, nExportFormat ) );
844  std::unique_ptr<SvStream> pOStm(::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), StreamMode::WRITE | StreamMode::TRUNC ));
845 
846  if( pOStm )
847  {
848  pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
849 
850  if( ConvertDataFormat::SVM == nExportFormat )
851  {
852  GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
853 
854  aMtf.Write( *pOStm );
855  bRet = ( pOStm->GetError() == ERRCODE_NONE );
856  }
857  else
858  {
859  if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
860  {
861  pOStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
862  bRet = ( pOStm->GetError() == ERRCODE_NONE );
863  }
864  else
865  bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
866  }
867 
868  pOStm.reset();
869  }
870 
871  if( bRet )
872  {
873  const SgaObjectBmp aObjBmp( aURL );
874  InsertObject( aObjBmp, nInsertPos );
875  }
876  }
877 
878  return bRet;
879 }
880 
881 bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
882 {
883  const GalleryObject* pObject = ImplGetGalleryObject( nPos );
884  bool bRet = false;
885 
886  if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
887  {
888  const INetURLObject aURL( ImplGetURL( pObject ) );
890 
891  if( xStor.is() )
892  {
893  const OUString aStmName( GetSvDrawStreamNameFromURL( aURL ) );
894  tools::SvRef<SotStorageStream> xIStm( xStor->OpenSotStream( aStmName, StreamMode::READ ) );
895 
896  if( xIStm.is() && !xIStm->GetError() )
897  {
898  xIStm->SetBufferSize( STREAMBUF_SIZE );
899  bRet = GallerySvDrawImport( *xIStm, rModel );
900  xIStm->SetBufferSize( 0 );
901  }
902  }
903  }
904 
905  return bRet;
906 }
907 
908 bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
909 {
912  bool bRet = false;
913 
914  if( xStor.is() )
915  {
916  const OUString aStmName( GetSvDrawStreamNameFromURL( aURL ) );
917  tools::SvRef<SotStorageStream> xOStm( xStor->OpenSotStream( aStmName, StreamMode::WRITE | StreamMode::TRUNC ) );
918 
919  if( xOStm.is() && !xOStm->GetError() )
920  {
921  SvMemoryStream aMemStm( 65535, 65535 );
922  FmFormModel* pFormModel = const_cast<FmFormModel*>(&rModel);
923 
924  pFormModel->BurnInStyleSheetAttributes();
925 
926  {
927  uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
928 
929  if (xDocOut.is())
930  (void)SvxDrawingLayerExport( pFormModel, xDocOut );
931  }
932 
933  aMemStm.Seek( 0 );
934 
935  xOStm->SetBufferSize( 16348 );
936  GalleryCodec aCodec( *xOStm );
937  aCodec.Write( aMemStm );
938 
939  if( !xOStm->GetError() )
940  {
941  SgaObjectSvDraw aObjSvDraw( rModel, aURL );
942  bRet = InsertObject( aObjSvDraw, nInsertPos );
943  }
944 
945  xOStm->SetBufferSize( 0 );
946  xOStm->Commit();
947  }
948  }
949 
950  return bRet;
951 }
952 
953 bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream> const & rxModelStream)
954 {
955  const GalleryObject* pObject = ImplGetGalleryObject( nPos );
956  bool bRet = false;
957 
958  if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
959  {
960  const INetURLObject aURL( ImplGetURL( pObject ) );
962 
963  if( xStor.is() )
964  {
965  const OUString aStmName( GetSvDrawStreamNameFromURL( aURL ) );
966  tools::SvRef<SotStorageStream> xIStm( xStor->OpenSotStream( aStmName, StreamMode::READ ) );
967 
968  if( xIStm.is() && !xIStm->GetError() )
969  {
970  sal_uInt32 nVersion = 0;
971 
972  xIStm->SetBufferSize( 16348 );
973 
974  if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
975  {
976  SvxGalleryDrawModel aModel;
977 
978  if( aModel.GetModel() )
979  {
980  if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
981  {
983 
984  {
985  uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
986 
987  if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
988  rxModelStream->Commit();
989  }
990  }
991 
992  bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
993  }
994  }
995 
996  xIStm->SetBufferSize( 0 );
997  }
998  }
999  }
1000 
1001  return bRet;
1002 }
1003 
1004 bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, sal_uInt32 nInsertPos)
1005 {
1008  bool bRet = false;
1009 
1010  if( xStor.is() )
1011  {
1012  const OUString aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1013  tools::SvRef<SotStorageStream> xOStm( xStor->OpenSotStream( aStmName, StreamMode::WRITE | StreamMode::TRUNC ) );
1014 
1015  if( xOStm.is() && !xOStm->GetError() )
1016  {
1017  GalleryCodec aCodec( *xOStm );
1018 
1019  xOStm->SetBufferSize( 16348 );
1020  aCodec.Write( *rxModelStream );
1021 
1022  if( !xOStm->GetError() )
1023  {
1024  xOStm->Seek( 0 );
1025  SgaObjectSvDraw aObjSvDraw( *xOStm, aURL );
1026  bRet = InsertObject( aObjSvDraw, nInsertPos );
1027  }
1028 
1029  xOStm->SetBufferSize( 0 );
1030  xOStm->Commit();
1031  }
1032  }
1033 
1034  return bRet;
1035 }
1036 
1037 bool GalleryTheme::GetURL(sal_uInt32 nPos, INetURLObject& rURL)
1038 {
1039  const GalleryObject* pObject = ImplGetGalleryObject( nPos );
1040  bool bRet = false;
1041 
1042  if( pObject )
1043  {
1044  rURL = ImplGetURL( pObject );
1045  bRet = true;
1046  }
1047 
1048  return bRet;
1049 }
1050 
1051 bool GalleryTheme::InsertURL(const INetURLObject& rURL, sal_uInt32 nInsertPos)
1052 {
1053  Graphic aGraphic;
1054  OUString aFormat;
1055  std::unique_ptr<SgaObject> pNewObj;
1056  const GalleryGraphicImportRet nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
1057  bool bRet = false;
1058 
1059  if( nImportRet != GalleryGraphicImportRet::IMPORT_NONE )
1060  {
1061  if ( aGraphic.IsAnimated() )
1062  pNewObj.reset(new SgaObjectAnim( aGraphic, rURL ));
1063  else
1064  pNewObj.reset(new SgaObjectBmp( aGraphic, rURL ));
1065  }
1066 #if HAVE_FEATURE_AVMEDIA
1068  pNewObj.reset(new SgaObjectSound( rURL ));
1069 #endif
1070  if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
1071  bRet = true;
1072 
1073  return bRet;
1074 }
1075 
1076 bool GalleryTheme::InsertFileOrDirURL(const INetURLObject& rFileOrDirURL, sal_uInt32 nInsertPos)
1077 {
1079  ::std::vector< INetURLObject > aURLVector;
1080  bool bRet = false;
1081 
1082  try
1083  {
1084  ::ucbhelper::Content aCnt( rFileOrDirURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
1085  bool bFolder = false;
1086 
1087  aCnt.getPropertyValue("IsFolder") >>= bFolder;
1088 
1089  if( bFolder )
1090  {
1091  uno::Sequence<OUString> aProps { "Url" };
1092  uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
1093  uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1094  if( xContentAccess.is() )
1095  {
1096  while( xResultSet->next() )
1097  {
1098  aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
1099  aURLVector.push_back( aURL );
1100  }
1101  }
1102  }
1103  else
1104  aURLVector.push_back( rFileOrDirURL );
1105  }
1106  catch( const ucb::ContentCreationException& )
1107  {
1108  }
1109  catch( const uno::RuntimeException& )
1110  {
1111  }
1112  catch( const uno::Exception& )
1113  {
1114  }
1115 
1116  for( const auto& rURL : aURLVector )
1117  bRet = bRet || InsertURL( rURL, nInsertPos );
1118 
1119  return bRet;
1120 }
1121 
1122 bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uInt32 nInsertPos)
1123 {
1124  bool bRet = false;
1125 
1126  if( rxTransferable.is() )
1127  {
1128  TransferableDataHelper aDataHelper( rxTransferable );
1129  std::unique_ptr<Graphic> pGraphic;
1130 
1131  if( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
1132  {
1134 
1135  if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xModelStm ) )
1136  bRet = InsertModelStream( xModelStm, nInsertPos );
1137  }
1138  else if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) ||
1139  aDataHelper.HasFormat( SotClipboardFormatId::SIMPLE_FILE ) )
1140  {
1141  FileList aFileList;
1142 
1143  if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) )
1144  aDataHelper.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList );
1145  else
1146  {
1147  OUString aFile;
1148  if (aDataHelper.GetString(SotClipboardFormatId::SIMPLE_FILE, aFile) && !aFile.isEmpty())
1149  aFileList.AppendFile( aFile );
1150  }
1151 
1152  for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
1153  {
1154  const OUString aFile( aFileList.GetFile( i ) );
1155  INetURLObject aURL( aFile );
1156 
1157  if( aURL.GetProtocol() == INetProtocol::NotValid )
1158  {
1159  OUString aLocalURL;
1160 
1161  if( osl::FileBase::getFileURLFromSystemPath( aFile, aLocalURL ) == osl::FileBase::E_None )
1162  aURL = INetURLObject( aLocalURL );
1163  }
1164 
1165  if( aURL.GetProtocol() != INetProtocol::NotValid )
1166  bRet = InsertFileOrDirURL( aURL, nInsertPos );
1167  }
1168  }
1169  else
1170  {
1171  Graphic aGraphic;
1172  SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
1173 
1174  if( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
1175  nFormat = SotClipboardFormatId::SVXB;
1176  else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ) )
1177  nFormat = SotClipboardFormatId::GDIMETAFILE;
1178  else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ) )
1179  nFormat = SotClipboardFormatId::BITMAP;
1180 
1181  if( nFormat != SotClipboardFormatId::NONE && aDataHelper.GetGraphic( nFormat, aGraphic ) )
1182  pGraphic.reset(new Graphic( aGraphic ));
1183  }
1184 
1185  if( pGraphic )
1186  {
1187  bRet = false;
1188 
1189  if( aDataHelper.HasFormat( SotClipboardFormatId::SVIM ) )
1190  {
1191 
1192  ImageMap aImageMap;
1193 
1194  // according to KA we don't need a BaseURL here
1195  if( aDataHelper.GetImageMap( SotClipboardFormatId::SVIM, aImageMap ) )
1196  {
1197  SvxGalleryDrawModel aModel;
1198 
1199  if( aModel.GetModel() )
1200  {
1201  SdrPage* pPage = aModel.GetModel()->GetPage(0);
1202  SdrGrafObj* pGrafObj = new SdrGrafObj(*aModel.GetModel(), *pGraphic );
1203 
1204  pGrafObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new SgaIMapInfo( aImageMap )) );
1205  pPage->InsertObject( pGrafObj );
1206  bRet = InsertModel( *aModel.GetModel(), nInsertPos );
1207  }
1208  }
1209  }
1210 
1211  if( !bRet )
1212  bRet = InsertGraphic( *pGraphic, nInsertPos );
1213  }
1214  }
1215 
1216  return bRet;
1217 }
1218 
1219 void GalleryTheme::CopyToClipboard(sal_uInt32 nPos)
1220 {
1221  GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
1222  pTransferable->CopyToClipboard(GetSystemClipboard());
1223 }
1224 
1226 {
1227  const INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1228  const INetURLObject aRelURL2( GetParent()->GetUserURL() );
1229  sal_uInt32 nCount = GetObjectCount();
1230  bool bRel;
1231 
1232  rOStm.WriteUInt16( 0x0004 );
1233  write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(), RTL_TEXTENCODING_UTF8);
1234  rOStm.WriteUInt32( nCount ).WriteUInt16( osl_getThreadTextEncoding() );
1235 
1236  for( sal_uInt32 i = 0; i < nCount; i++ )
1237  {
1238  const GalleryObject* pObj = ImplGetGalleryObject( i );
1239  OUString aPath;
1240 
1241  if( SgaObjKind::SvDraw == pObj->eObjKind )
1242  {
1243  aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
1244  bRel = false;
1245  }
1246  else
1247  {
1249  aPath = aPath.copy( 0, std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
1250  bRel = aPath == aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE );
1251 
1252  if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) )
1253  {
1255  aPath = aPath.copy( std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
1256  }
1257  else
1258  {
1260  aPath = aPath.copy( 0, std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
1261  bRel = aPath == aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE );
1262 
1263  if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) )
1264  {
1266  aPath = aPath.copy( std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
1267  }
1268  else
1270  }
1271  }
1272 
1273  if ( !m_aDestDir.isEmpty() )
1274  {
1275  bool aFound = aPath.indexOf(m_aDestDir) != -1;
1276  aPath = aPath.replaceFirst(m_aDestDir, "");
1277  if ( aFound )
1278  bRel = m_bDestDirRelative;
1279  else
1280  SAL_WARN( "svx", "failed to replace destdir of '"
1281  << m_aDestDir << "' in '" << aPath << "'");
1282  }
1283 
1284  rOStm.WriteBool( bRel );
1285  write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
1286  rOStm.WriteUInt32( pObj->nOffset ).WriteUInt16( static_cast<sal_uInt16>(pObj->eObjKind) );
1287  }
1288 
1289  // more recently, a 512-byte reserve buffer is written,
1290  // to recognize them two sal_uInt32-Ids will be written.
1291  rOStm.WriteUInt32( COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) ).WriteUInt32( COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) );
1292 
1293  const long nReservePos = rOStm.Tell();
1294  std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStm, StreamMode::WRITE, 2 ));
1295 
1296  rOStm.WriteUInt32( GetId() ).WriteBool( pThm->IsNameFromResource() ); // From version 2 and up
1297 
1298  pCompat.reset();
1299 
1300  // Fill the rest of the buffer.
1301  const long nRest = std::max( 512L - ( static_cast<long>(rOStm.Tell()) - nReservePos ), 0L );
1302 
1303  if( nRest )
1304  {
1305  std::unique_ptr<char[]> pReserve(new char[ nRest ]);
1306  memset( pReserve.get(), 0, nRest );
1307  rOStm.WriteBytes(pReserve.get(), nRest);
1308  }
1309 
1310  return rOStm;
1311 }
1312 
1314 {
1315  sal_uInt32 nCount;
1316  sal_uInt16 nVersion;
1317 
1318  rIStm.ReadUInt16( nVersion );
1320  rIStm.ReadUInt32( nCount );
1321 
1322  if( nVersion >= 0x0004 )
1323  {
1324  sal_uInt16 nTmp16;
1325  rIStm.ReadUInt16( nTmp16 );
1326  }
1327 
1328  if( nCount <= ( 1 << 14 ) )
1329  {
1330  INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1331  INetURLObject aRelURL2( GetParent()->GetUserURL() );
1332  sal_uInt32 nId1, nId2;
1333  bool bRel;
1334 
1335  for(auto & i : aObjectList)
1336  {
1337  GalleryObject* pObj = i.get();
1339  i.reset();
1340  }
1341  aObjectList.clear();
1342 
1343  for( sal_uInt32 i = 0; i < nCount; i++ )
1344  {
1345  std::unique_ptr<GalleryObject> pObj(new GalleryObject);
1346 
1347  OUString aFileName;
1348  OUString aPath;
1349  sal_uInt16 nTemp;
1350 
1351  rIStm.ReadCharAsBool( bRel );
1352  OString aTempFileName = read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm);
1353  rIStm.ReadUInt32( pObj->nOffset );
1354  rIStm.ReadUInt16( nTemp ); pObj->eObjKind = static_cast<SgaObjKind>(nTemp);
1355 
1356  aFileName = OStringToOUString(aTempFileName, osl_getThreadTextEncoding());
1357 
1358  if( bRel )
1359  {
1360  aFileName = aFileName.replaceAll( "\\", "/" );
1362 
1363  if( aFileName[ 0 ] != '/' )
1364  aPath += "/";
1365 
1366  aPath += aFileName;
1367 
1368  pObj->aURL = INetURLObject( aPath );
1369 
1370  if( !FileExists( pObj->aURL ) )
1371  {
1373 
1374  if( aFileName[0] != '/' )
1375  aPath += "/";
1376 
1377  aPath += aFileName;
1378 
1379  // assign this URL, even in the case it is not valid (#94482)
1380  pObj->aURL = INetURLObject( aPath );
1381  }
1382  }
1383  else
1384  {
1385  if( SgaObjKind::SvDraw == pObj->eObjKind )
1386  {
1387  OUString aDummyURL( "gallery/svdraw/" );
1388  pObj->aURL = INetURLObject( aDummyURL += aFileName, INetProtocol::PrivSoffice );
1389  }
1390  else
1391  {
1392  OUString aLocalURL;
1393 
1394  pObj->aURL = INetURLObject( aFileName );
1395 
1396  if( ( pObj->aURL.GetProtocol() == INetProtocol::NotValid ) &&
1397  osl::FileBase::getFileURLFromSystemPath( aFileName, aLocalURL ) == osl::FileBase::E_None )
1398  {
1399  pObj->aURL = INetURLObject( aLocalURL );
1400  }
1401  }
1402  }
1403  aObjectList.push_back( std::move(pObj) );
1404  }
1405 
1406  rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 );
1407 
1408  // In newer versions a 512 byte reserve buffer is located at the end,
1409  // the data is located at the beginning of this buffer and are clamped
1410  // by a VersionCompat.
1411  if( !rIStm.eof() &&
1412  nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1413  nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1414  {
1415  VersionCompat aCompat( rIStm, StreamMode::READ );
1416  sal_uInt32 nTemp32;
1417  bool bThemeNameFromResource = false;
1418 
1419  rIStm.ReadUInt32( nTemp32 );
1420 
1421  if( aCompat.GetVersion() >= 2 )
1422  {
1423  rIStm.ReadCharAsBool( bThemeNameFromResource );
1424  }
1425 
1426  SetId( nTemp32, bThemeNameFromResource );
1427  }
1428  }
1429  else
1430  rIStm.SetError( SVSTREAM_READ_ERROR );
1431 
1432  ImplSetModified( false );
1433 
1434  return rIStm;
1435 }
1436 
1438 {
1439  return rTheme.WriteData( rOut );
1440 }
1441 
1443 {
1444  return rTheme.ReadData( rIn );
1445 }
1446 
1447 void GalleryTheme::ImplSetModified( bool bModified )
1448 {
1449  pThm->SetModified(bModified);
1450 }
1451 
1456 sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
1457 void GalleryTheme::SetId( sal_uInt32 nNewId, bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
1458 bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
1459 bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
1460 
1462 {
1463  return aSvDrawStorageRef;
1464 }
1465 
1466 const OUString& GalleryTheme::GetName() const { return pThm->GetThemeName(); }
1467 
1468 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream & WriteBool(bool b)
bool is() const
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic)
URL aURL
bool InsertObject(const SgaObject &rObj, sal_uInt32 nPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:360
void Update(sal_Int32 nVal, sal_Int32 nMaxVal)
Definition: galmisc.cxx:349
const INetURLObject & GetStrURL() const
Definition: gallery1.hxx:61
bool IsModified() const
Definition: gallery1.hxx:70
bool IsDefault() const
Definition: galtheme.cxx:1459
sal_uInt32 GetId() const
Definition: galtheme.cxx:1456
bool InsertGraphic(const Graphic &rGraphic, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:799
SvStream & WriteUInt16(sal_uInt16 nUInt16)
bool CreateIMapGraphic(const FmFormModel &rModel, Graphic &rGraphic, ImageMap &rImageMap)
Definition: galmisc.cxx:119
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
sal_uInt32 mnBroadcasterLockCount
Definition: galtheme.hxx:83
SvStream & ReadSgaObject(SvStream &rIn, SgaObject &rObj)
Definition: galobj.cxx:226
static SAL_DLLPRIVATE GalleryThemeEntry * CreateThemeEntry(const INetURLObject &rURL, bool bReadOnly)
Definition: galtheme.cxx:644
SAL_DLLPRIVATE Gallery * GetParent() const
Definition: galtheme.hxx:164
sal_uInt32 mnThemeLockCount
Definition: galtheme.hxx:82
const INetURLObject & GetSdgURL() const
Definition: galtheme.cxx:1453
#define SVSTREAM_READ_ERROR
SAL_DLLPRIVATE SvStream & WriteData(SvStream &rOut) const
Definition: galtheme.cxx:1225
bool SvxDrawingLayerExport(SdrModel *pModel, const uno::Reference< io::XOutputStream > &xOut, const Reference< lang::XComponent > &xComponent)
Definition: xmlexport.cxx:42
ErrCode GetError() const
css::uno::Any getPropertyValue(const OUString &rPropertyName)
SAL_DLLPRIVATE bool InsertModelStream(const tools::SvRef< SotStorageStream > &rModelStream, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:1004
SvStream & ReadCharAsBool(bool &rBool)
sal_Int64 n
OUString maPath
Definition: galtheme.hxx:50
#define STREAM_SEEK_TO_END
void RemoveObject(sal_uInt32 nPos)
Definition: galtheme.cxx:430
sal_uInt64 Seek(sal_uInt64 nPos)
SvStream & WriteSgaObject(SvStream &rOut, const SgaObject &rObj)
Definition: galobj.cxx:220
css::uno::Reference< css::datatransfer::clipboard::XClipboard > VCL_DLLPUBLIC GetSystemClipboard()
SAL_DLLPRIVATE void SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx &rBitmapEx, const Size &rSize, const OUString &rTitle, const OUString &rPath)
Definition: galtheme.cxx:420
FmFormModel * GetModel() const
bool IsReadOnly() const
Definition: gallery1.hxx:65
bool bReadOnly
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:351
EmbeddedObjectRef * pObject
bool HasFormat(SotClipboardFormatId nFormat) const
void BurnInStyleSheetAttributes()
Definition: svdmodel.cxx:823
SAL_DLLPRIVATE void GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx &rBitmapEx, Size &rSize, OUString &rTitle, OUString &rPath) const
Definition: galtheme.cxx:410
bool CreateDir(const INetURLObject &rURL)
Definition: galmisc.cxx:226
void Clear()
OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
SAL_DLLPRIVATE bool GetURL(sal_uInt32 nPos, INetURLObject &rURL)
Definition: galtheme.cxx:1037
tools::SvRef< SotStorage > aSvDrawStorageRef
Definition: galtheme.hxx:79
SvStream & ReadGalleryTheme(SvStream &rIn, GalleryTheme &rTheme)
Definition: galtheme.cxx:1442
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool eof() const
SgaObjKind eObjKind
Definition: galtheme.hxx:43
static SAL_DLLPRIVATE INetURLObject ImplGetURL(const GalleryObject *pObject)
Definition: galtheme.cxx:226
int nCount
GalleryThemeEntry * pThm
Definition: galtheme.hxx:81
INetURLObject aURL
Definition: galtheme.hxx:41
bool CopyTo(SotStorage *pDestStg)
const GDIMetaFile & GetGDIMetaFile() const
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SAL_DLLPRIVATE SvStream & ReadData(SvStream &rIn)
Definition: galtheme.cxx:1313
BitmapEx maPreviewBitmapEx
Definition: galtheme.hxx:47
SotClipboardFormatId
SAL_DLLPRIVATE const INetURLObject & GetStrURL() const
Definition: galtheme.cxx:1455
virtual SAL_DLLPRIVATE ~GalleryTheme() override
Definition: galtheme.cxx:76
SAL_DLLPRIVATE void LockBroadcaster()
Definition: galtheme.hxx:151
bool IsAnimated() const
bool m_bDestDirRelative
Definition: galtheme.hxx:78
SAL_DLLPRIVATE void ImplCreateSvDrawStorage()
Definition: galtheme.cxx:89
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SgaObjKind
Definition: galmisc.hxx:54
T * get() const
sal_uInt32 GetId() const
Definition: gallery1.hxx:76
#define SOFFICE_FILEFORMAT_50
::std::vector< std::unique_ptr< GalleryObject > > aObjectList
Definition: galtheme.hxx:76
#define TOOLS_WARN_EXCEPTION(area, stream)
SAL_DLLPRIVATE bool InsertFileOrDirURL(const INetURLObject &rFileOrDirURL, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:1076
#define ERRCODE_IO_GENERAL
#define DBG_ASSERT(sCon, aError)
int i
OUString m_aDestDir
Definition: galtheme.hxx:77
GalleryGraphicImportRet GalleryGraphicImport(const INetURLObject &rURL, Graphic &rGraphic, OUString &rFilterName)
Definition: galmisc.cxx:50
SotStorageStream * OpenSotStream(const OUString &rEleName, StreamMode=StreamMode::STD_READWRITE)
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:1051
bool Append(OUString const &rTheSegment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
GraphicType GetType() const
OUString const & GetURL() const
void SetModified(bool bSet)
Definition: gallery1.hxx:71
sal_uInt32 COMPAT_FORMAT(char char1, char char2, char char3, char char4)
void Actualize(const Link< const INetURLObject &, void > &rActualizeLink, GalleryProgress *pProgress=nullptr)
Definition: galtheme.cxx:470
sal_uInt32 nOffset
Definition: galtheme.hxx:42
bool GetString(SotClipboardFormatId nFormat, OUString &rStr)
SAL_DLLPRIVATE const tools::SvRef< SotStorage > & GetSvDrawStorage() const
Definition: galtheme.cxx:1461
ConvertDataFormat
SAL_DLLPRIVATE void ImplWrite()
Definition: galtheme.cxx:188
void hideMarkHandles()
Definition: svdmrkv.cxx:548
SAL_DLLPRIVATE bool ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
Definition: galtheme.cxx:449
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1903
Size maPreparedSize
Definition: galtheme.hxx:48
std::size_t WriteBytes(const void *pData, std::size_t nSize)
OUString GetFile(size_t nIndex) const
void SetError(ErrCode nErrorCode)
SAL_DLLPRIVATE bool InsertTransferable(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:1122
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
Definition: galtheme.hxx:123
GalleryGraphicImportRet
Definition: galmisc.hxx:68
bool GetGraphic(sal_uInt32 nPos, Graphic &rGraphic)
Definition: galtheme.cxx:727
void CopyToClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard) const
bool removeFinalSlash()
This class represents an embedded or linked bitmap graphic object.
Definition: svdograf.hxx:79
sal_Int16 nVersion
GfxLink GetGfxLink() const
bool KillFile(const INetURLObject &rURL)
Definition: galmisc.cxx:287
size_t Count() const
void AppendFile(const OUString &rStr)
SAL_DLLPRIVATE bool IsBroadcasterLocked() const
Definition: galtheme.hxx:153
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
bool GallerySvDrawImport(SvStream &rIStm, SdrModel &rModel)
Definition: galmisc.cxx:75
void UnlockBroadcaster()
Definition: galtheme.cxx:352
SvStream & WriteGalleryTheme(SvStream &rOut, const GalleryTheme &rTheme)
Definition: galtheme.cxx:1437
bool IsNameFromResource() const
Definition: gallery1.hxx:74
SAL_DLLPRIVATE void ImplBroadcast(sal_uInt32 nUpdatePos)
Definition: galtheme.cxx:326
void AppendUserData(std::unique_ptr< SdrObjUserData > pData)
Definition: svdobj.cxx:2614
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotStorageStream > &rStreamRef)
bool GetImageMap(SotClipboardFormatId nFormat, ImageMap &rIMap)
bool IsDefault() const
Definition: gallery1.cxx:761
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
std::unique_ptr< SgaObject > ImplReadSgaObject(GalleryObject const *pEntry)
Definition: galtheme.cxx:144
bool CopyFile(const INetURLObject &rSrcURL, const INetURLObject &rDstURL)
Definition: galmisc.cxx:261
SAL_DLLPRIVATE bool GetModelStream(sal_uInt32 nPos, tools::SvRef< SotStorageStream > const &rModelStreamRef)
Definition: galtheme.cxx:953
static ErrCode Export(SvStream &rOStm, const Graphic &rGraphic, ConvertDataFormat nFormat)
bool GetModel(sal_uInt32 nPos, SdrModel &rModel)
Definition: galtheme.cxx:881
SAL_DLLPRIVATE const GalleryObject * ImplGetGalleryObject(sal_uInt32 nPos) const
Definition: galtheme.hxx:92
SAL_DLLPRIVATE void CopyToClipboard(sal_uInt32 nPos)
Definition: galtheme.cxx:1219
void Broadcast(const SfxHint &rHint)
#define ERRCODE_NONE
INetProtocol GetProtocol() const
void SetId(sal_uInt32 nNewId, bool bResetThemeName)
Definition: gallery1.cxx:226
SAL_DLLPRIVATE bool GetThumb(sal_uInt32 nPos, BitmapEx &rBmp)
Definition: galtheme.cxx:713
void Write(SvStream &rStmToWrite)
Definition: codec.cxx:60
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList)
sal_uInt64 Tell() const
void * p
Reference< XComponentContext > getProcessComponentContext()
SAL_DLLPRIVATE GalleryTheme(Gallery *pGallery, GalleryThemeEntry *pThemeEntry)
Definition: galtheme.cxx:63
SAL_DLLPRIVATE const INetURLObject & GetThmURL() const
Definition: galtheme.cxx:1452
SAL_DLLPRIVATE bool ImplWriteSgaObject(const SgaObject &rObj, sal_uInt32 nPos, GalleryObject *pExistentEntry)
Definition: galtheme.cxx:106
bool bAbortActualize
Definition: galtheme.hxx:86
static bool IsCoded(SvStream &rStm, sal_uInt32 &rVersion)
Definition: codec.cxx:36
SAL_DLLPRIVATE void ImplSetModified(bool bModified)
Definition: galtheme.cxx:1447
SAL_DLLPRIVATE void SetId(sal_uInt32 nNewId, bool bResetThemeName)
Definition: galtheme.cxx:1457
#define SAL_WARN(area, stream)
OUString GetSvDrawStreamNameFromURL(const INetURLObject &rSvDrawObjURL)
Definition: galmisc.cxx:185
const OUString & GetName() const
Definition: galtheme.cxx:1466
SAL_DLLPRIVATE INetURLObject ImplCreateUniqueURL(SgaObjKind eObjKind, ConvertDataFormat nFormat=ConvertDataFormat::Unknown)
Definition: galtheme.cxx:236
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
SAL_DLLPRIVATE bool UnlockTheme()
Definition: galtheme.cxx:337
bool IsReadOnly() const
Definition: galtheme.cxx:1458
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream &rStrm, const OUString &rStr, rtl_TextEncoding eEnc)
const char * pExt
Definition: xtable.cxx:371
OUString maTitle
Definition: galtheme.hxx:49
bool InsertModel(const FmFormModel &rModel, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:908
#define STREAMBUF_SIZE
Definition: galmisc.hxx:66
const INetURLObject & GetSdvURL() const
Definition: gallery1.hxx:60
static bool FileExists(const INetURLObject &rURL, const OUString &rExt)
Definition: gallery1.cxx:53
INCLUDE_DOCUMENTS_ONLY
bool Remove(const OUString &rEleName)
const OUString & GetThemeName() const
Definition: gallery1.hxx:56
SvStream & Write(SvStream &rOStm)
const INetURLObject & GetSdgURL() const
Definition: gallery1.hxx:59
SAL_DLLPRIVATE const INetURLObject & GetSdvURL() const
Definition: galtheme.cxx:1454
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
Definition: galtheme.cxx:405
const INetURLObject & GetThmURL() const
Definition: gallery1.hxx:58