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