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>
54 #include <com/sun/star/sdbc/XResultSet.hpp>
55 #include <com/sun/star/ucb/XContentAccess.hpp>
56 #include <galobj.hxx>
57 #include <svx/gallery1.hxx>
58 #include "gallerydrawmodel.hxx"
59 #include <memory>
60 
61 using namespace ::com::sun::star;
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  if(pThm->IsModified())
79  if(!mpGalleryBinaryEngine->implWrite(*this))
80  ImplSetModified(false);
81 
82  for (auto & pEntry : maGalleryObjectCollection.getObjectList())
83  {
85  pEntry.reset();
86  }
88  mpGalleryBinaryEngine->clearSotStorage();
89 }
90 
91 std::unique_ptr<GalleryBinaryEngine> GalleryTheme::createGalleryBinaryEngine(bool bReadOnly)
92 {
93  std::unique_ptr<GalleryBinaryEngine> pGalleryBinaryEngine = std::make_unique<GalleryBinaryEngine>(pThm->getGalleryStorageLocations(), maGalleryObjectCollection, bReadOnly);
94  return pGalleryBinaryEngine;
95 }
96 
97 void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos)
98 {
99  if( !IsBroadcasterLocked() )
100  {
101  if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
102  nUpdatePos = GetObjectCount() - 1;
103 
104  Broadcast( GalleryHint( GalleryHintType::THEME_UPDATEVIEW, GetName(), reinterpret_cast<void*>(nUpdatePos) ) );
105  }
106 }
107 
109 {
110  DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
111 
112  bool bRet = false;
113 
114  if( mnThemeLockCount )
115  {
117  bRet = true;
118  }
119 
120  return bRet;
121 }
122 
124 {
125  DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
126 
128  ImplBroadcast( 0 );
129 }
130 
131 bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
132 {
133  if (!rObj.IsValid())
134  return false;
135 
136  GalleryObject* pFoundEntry = nullptr;
137  sal_uInt32 iFoundPos = 0;
138  for (sal_uInt32 n = maGalleryObjectCollection.size(); iFoundPos < n; ++iFoundPos)
139  {
140  if (maGalleryObjectCollection.get(iFoundPos)->aURL == rObj.GetURL())
141  {
142  pFoundEntry = maGalleryObjectCollection.get(iFoundPos).get();
143  break;
144  }
145  }
146 
147  mpGalleryBinaryEngine->insertObject(rObj, pFoundEntry, m_aDestDir, nInsertPos);
148 
149  ImplSetModified(true);
150  ImplBroadcast(pFoundEntry? iFoundPos: nInsertPos);
151 
152  return true;
153 }
154 
155 std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
156 {
157  return mpGalleryBinaryEngine->implReadSgaObject(maGalleryObjectCollection.getForPosition(nPos));
158 }
159 
160 void GalleryTheme::GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx& rBitmapEx, Size& rSize, OUString& rTitle, OUString& rPath)
161 {
162  const GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get();
163 
164  rBitmapEx = pGalleryObject->maPreviewBitmapEx;
165  rSize = pGalleryObject->maPreparedSize;
166  rTitle = pGalleryObject->maTitle;
167  rPath = pGalleryObject->maPath;
168 }
169 
170 void GalleryTheme::SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx& rBitmapEx, const Size& rSize, const OUString& rTitle, const OUString& rPath)
171 {
172  GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get();
173 
174  pGalleryObject->maPreviewBitmapEx = rBitmapEx;
175  pGalleryObject->maPreparedSize = rSize;
176  pGalleryObject->maTitle = rTitle;
177  pGalleryObject->maPath = rPath;
178 }
179 
180 void GalleryTheme::RemoveObject(sal_uInt32 nPos)
181 {
182  auto it = maGalleryObjectCollection.getObjectList().begin() + nPos;
183  std::unique_ptr<GalleryObject> pEntry = std::move(*it);
185 
187  KillFile( GetSdgURL() );
188 
189  if( SgaObjKind::SvDraw == pEntry->eObjKind )
190  mpGalleryBinaryEngine->GetSvDrawStorage()->Remove( pEntry->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
191 
193  pEntry.reset();
194 
195  ImplSetModified( true );
196  ImplBroadcast( nPos );
197 }
198 
199 bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
200 {
201  if (nOldPos == nNewPos || nOldPos >= maGalleryObjectCollection.size())
202  return false;
203 
204  std::unique_ptr<GalleryObject> pEntry = std::move(maGalleryObjectCollection.get(nOldPos));
205 
206  maGalleryObjectCollection.getObjectList().insert(maGalleryObjectCollection.getObjectList().begin() + nNewPos, std::move(pEntry));
207 
208  if (nNewPos < nOldPos)
209  nOldPos++;
210 
211  auto it = maGalleryObjectCollection.getObjectList().begin() + nOldPos;
213 
214  ImplSetModified(true);
215  ImplBroadcast((nNewPos < nOldPos)? nNewPos: (nNewPos - 1));
216 
217  return true;
218 }
219 
221 {
222  if( IsReadOnly() )
223  return;
224 
225  Graphic aGraphic;
226  OUString aFormat;
227  const sal_uInt32 nCount = maGalleryObjectCollection.size();
228 
229  LockBroadcaster();
230  bAbortActualize = false;
231 
232  // reset delete flag
233  for (sal_uInt32 i = 0; i < nCount; i++)
234  maGalleryObjectCollection.get(i)->mbDelete = false;
235 
236  for (sal_uInt32 i = 0; ( i < nCount ) && !bAbortActualize; i++)
237  {
238  if( pProgress )
239  pProgress->Update( i, nCount - 1 );
240 
241  GalleryObject* pEntry = maGalleryObjectCollection.get(i).get();
242 
243  const INetURLObject aURL( pEntry->aURL );
244 
245  rActualizeLink.Call( aURL );
246 
247  // SvDraw objects will be updated later
248  if( pEntry->eObjKind != SgaObjKind::SvDraw )
249  {
250  // Still a function should be implemented,
251  // which assigns files to the relevant entry.
252  // insert graphics as graphic objects into the gallery
253  if( pEntry->eObjKind == SgaObjKind::Sound )
254  {
255  SgaObjectSound aObjSound( aURL );
256  if( !InsertObject( aObjSound ) )
257  pEntry->mbDelete = true;
258  }
259  else
260  {
261  aGraphic.Clear();
262 
263  if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) != GalleryGraphicImportRet::IMPORT_NONE )
264  {
265  std::unique_ptr<SgaObject> pNewObj;
266 
267  if ( SgaObjKind::Inet == pEntry->eObjKind )
268  pNewObj.reset(new SgaObjectINet( aGraphic, aURL ));
269  else if ( aGraphic.IsAnimated() )
270  pNewObj.reset(new SgaObjectAnim( aGraphic, aURL ));
271  else
272  pNewObj.reset(new SgaObjectBmp( aGraphic, aURL ));
273 
274  if( !InsertObject( *pNewObj ) )
275  pEntry->mbDelete = true;
276  }
277  else
278  pEntry->mbDelete = true; // set delete flag
279  }
280  }
281  else
282  {
283  //update SvDraw object
284  if ( mpGalleryBinaryEngine->GetSvDrawStorage().is() )
285  {
286  SgaObjectSvDraw aNewObj = mpGalleryBinaryEngine->updateSvDrawObject(pEntry);
287  if (aNewObj.IsValid() && !InsertObject(aNewObj))
288  pEntry->mbDelete = true;
289  }
290  }
291  }
292 
293  // remove all entries with set flag
294  for ( auto it = maGalleryObjectCollection.getObjectList().begin(); it != maGalleryObjectCollection.getObjectList().end(); /* increment is in the body of loop */)
295  {
296  if( (*it)->mbDelete )
297  {
299  it = maGalleryObjectCollection.getObjectList().erase( it );
300  }
301  else
302  ++it;
303  }
304 
305  // update theme
306  mpGalleryBinaryEngine->updateTheme();
307  ImplSetModified( true );
308  if (pThm->IsModified())
309  if (!mpGalleryBinaryEngine->implWrite(*this))
310  ImplSetModified(false);
312 }
313 
314 bool GalleryTheme::GetThumb(sal_uInt32 nPos, BitmapEx& rBmp)
315 {
316  std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
317  bool bRet = false;
318 
319  if( pObj )
320  {
321  rBmp = pObj->GetThumbBmp();
322  bRet = true;
323  }
324 
325  return bRet;
326 }
327 
328 bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
329 {
331  bool bRet = false;
332 
333  if( pObject )
334  {
335  const INetURLObject aURL( ImplGetURL( pObject ) );
336 
337  switch( pObject->eObjKind )
338  {
339  case SgaObjKind::Bitmap:
341  case SgaObjKind::Inet:
342  {
343  OUString aFilterDummy;
344  bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy ) != GalleryGraphicImportRet::IMPORT_NONE );
345  }
346  break;
347 
348  case SgaObjKind::SvDraw:
349  {
350  SvxGalleryDrawModel aModel;
351 
352  if( aModel.GetModel() )
353  {
354  if( GetModel( nPos, *aModel.GetModel() ) )
355  {
356  ImageMap aIMap;
357 
358  if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
359  bRet = true;
360  else
361  {
363  pVDev->SetMapMode( MapMode( MapUnit::Map100thMM ) );
364  FmFormView aView(*aModel.GetModel(), pVDev);
365 
366  aView.hideMarkHandles();
367  aView.ShowSdrPage(aView.GetModel()->GetPage(0));
368  aView.MarkAll();
369  rGraphic = aView.GetAllMarkedGraphic();
370  bRet = true;
371  }
372  }
373  }
374  }
375  break;
376 
377  case SgaObjKind::Sound:
378  {
379  std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
380 
381  if( pObj )
382  {
383  rGraphic = pObj->GetThumbBmp();
384  //Bitmap aBmp( pObj->GetThumbBmp() );
385  //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
386  //rGraphic = aBmp;
387  bRet = true;
388  }
389  }
390  break;
391 
392  default:
393  break;
394  }
395  }
396 
397  return bRet;
398 }
399 
400 bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos)
401 {
402  bool bRet = false;
403 
404  if( rGraphic.GetType() != GraphicType::NONE )
405  {
406  ConvertDataFormat nExportFormat = ConvertDataFormat::Unknown;
407  const GfxLink aGfxLink( rGraphic.GetGfxLink() );
408 
409  if( aGfxLink.GetDataSize() )
410  {
411  switch( aGfxLink.GetType() )
412  {
413  case GfxLinkType::EpsBuffer: nExportFormat = ConvertDataFormat::SVM; break;
414  case GfxLinkType::NativeGif: nExportFormat = ConvertDataFormat::GIF; break;
415 
416  // #i15508# added BMP type
417  // could not find/trigger a call to this, but should do no harm
418  case GfxLinkType::NativeBmp: nExportFormat = ConvertDataFormat::BMP; break;
419 
420  case GfxLinkType::NativeJpg: nExportFormat = ConvertDataFormat::JPG; break;
421  case GfxLinkType::NativePng: nExportFormat = ConvertDataFormat::PNG; break;
422  case GfxLinkType::NativeTif: nExportFormat = ConvertDataFormat::TIF; break;
423  case GfxLinkType::NativeWmf: nExportFormat = ConvertDataFormat::WMF; break;
424  case GfxLinkType::NativeMet: nExportFormat = ConvertDataFormat::MET; break;
425  case GfxLinkType::NativePct: nExportFormat = ConvertDataFormat::PCT; break;
426  case GfxLinkType::NativeSvg: nExportFormat = ConvertDataFormat::SVG; break;
427  default:
428  break;
429  }
430  }
431  else
432  {
433  if( rGraphic.GetType() == GraphicType::Bitmap )
434  {
435  if( rGraphic.IsAnimated() )
436  nExportFormat = ConvertDataFormat::GIF;
437  else
438  nExportFormat = ConvertDataFormat::PNG;
439  }
440  else
441  nExportFormat = ConvertDataFormat::SVM;
442  }
443 
444  const SgaObjectBmp aObjBmp = mpGalleryBinaryEngine->insertGraphic(rGraphic, aGfxLink, nExportFormat, GetParent()->GetUserURL());
445 
446  if (aObjBmp.IsValid())
447  bRet = InsertObject(aObjBmp, nInsertPos);
448  }
449 
450  return bRet;
451 }
452 
453 bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
454 {
456  bool bRet = false;
457 
458  if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
459  {
460  bRet = mpGalleryBinaryEngine->readModel(pObject, rModel);
461  }
462 
463  return bRet;
464 }
465 
466 bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
467 {
468  bool bRet = false;
469  SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModel(rModel, GetParent()->GetUserURL());
470  if(aObjSvDraw.IsValid())
471  bRet = InsertObject( aObjSvDraw, nInsertPos );
472  return bRet;
473 }
474 
475 bool GalleryTheme::GetModelStream(sal_uInt32 nPos, tools::SvRef<SotStorageStream> const & rxModelStream)
476 {
478  bool bRet = false;
479 
480  if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
481  {
482  bRet = mpGalleryBinaryEngine->readModelStream(pObject, rxModelStream);
483  }
484 
485  return bRet;
486 }
487 
488 bool GalleryTheme::InsertModelStream(const tools::SvRef<SotStorageStream>& rxModelStream, sal_uInt32 nInsertPos)
489 {
490  bool bRet = false;
491 
492  const SgaObjectSvDraw aObjSvDraw = mpGalleryBinaryEngine->insertModelStream(rxModelStream, GetParent()->GetUserURL());
493  if(aObjSvDraw.IsValid())
494  bRet = InsertObject( aObjSvDraw, nInsertPos );
495 
496  return bRet;
497 }
498 
499 bool GalleryTheme::GetURL(sal_uInt32 nPos, INetURLObject& rURL)
500 {
502  bool bRet = false;
503 
504  if( pObject )
505  {
506  rURL = ImplGetURL( pObject );
507  bRet = true;
508  }
509 
510  return bRet;
511 }
512 
513 bool GalleryTheme::InsertURL(const INetURLObject& rURL, sal_uInt32 nInsertPos)
514 {
515  Graphic aGraphic;
516  OUString aFormat;
517  std::unique_ptr<SgaObject> pNewObj;
518  const GalleryGraphicImportRet nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
519  bool bRet = false;
520 
521  if( nImportRet != GalleryGraphicImportRet::IMPORT_NONE )
522  {
523  if ( aGraphic.IsAnimated() )
524  pNewObj.reset(new SgaObjectAnim( aGraphic, rURL ));
525  else
526  pNewObj.reset(new SgaObjectBmp( aGraphic, rURL ));
527  }
528 #if HAVE_FEATURE_AVMEDIA
530  pNewObj.reset(new SgaObjectSound( rURL ));
531 #endif
532  if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
533  bRet = true;
534 
535  return bRet;
536 }
537 
538 bool GalleryTheme::InsertFileOrDirURL(const INetURLObject& rFileOrDirURL, sal_uInt32 nInsertPos)
539 {
540  bool bRet = false;
541  std::vector< INetURLObject > aURLVector;
542  GalleryBinaryEngine::insertFileOrDirURL(rFileOrDirURL, aURLVector);
543 
544  for( const auto& rURL : aURLVector )
545  bRet = bRet || InsertURL( rURL, nInsertPos );
546 
547  return bRet;
548 }
549 
550 bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uInt32 nInsertPos)
551 {
552  bool bRet = false;
553 
554  if( rxTransferable.is() )
555  {
556  TransferableDataHelper aDataHelper( rxTransferable );
557  std::unique_ptr<Graphic> pGraphic;
558 
559  if( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
560  {
562 
563  if( aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING, xModelStm ) )
564  bRet = InsertModelStream( xModelStm, nInsertPos );
565  }
566  else if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) ||
567  aDataHelper.HasFormat( SotClipboardFormatId::SIMPLE_FILE ) )
568  {
569  FileList aFileList;
570 
571  if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) )
572  aDataHelper.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList );
573  else
574  {
575  OUString aFile;
576  if (aDataHelper.GetString(SotClipboardFormatId::SIMPLE_FILE, aFile) && !aFile.isEmpty())
577  aFileList.AppendFile( aFile );
578  }
579 
580  for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
581  {
582  const OUString aFile( aFileList.GetFile( i ) );
583  INetURLObject aURL( aFile );
584 
585  if( aURL.GetProtocol() == INetProtocol::NotValid )
586  {
587  OUString aLocalURL;
588 
589  if( osl::FileBase::getFileURLFromSystemPath( aFile, aLocalURL ) == osl::FileBase::E_None )
590  aURL = INetURLObject( aLocalURL );
591  }
592 
593  if( aURL.GetProtocol() != INetProtocol::NotValid )
594  bRet = InsertFileOrDirURL( aURL, nInsertPos );
595  }
596  }
597  else
598  {
599  Graphic aGraphic;
600  SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
601 
602  if( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
603  nFormat = SotClipboardFormatId::SVXB;
604  else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ) )
605  nFormat = SotClipboardFormatId::GDIMETAFILE;
606  else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ) )
607  nFormat = SotClipboardFormatId::BITMAP;
608 
609  if( nFormat != SotClipboardFormatId::NONE && aDataHelper.GetGraphic( nFormat, aGraphic ) )
610  pGraphic.reset(new Graphic( aGraphic ));
611  }
612 
613  if( pGraphic )
614  {
615  bRet = false;
616 
617  if( aDataHelper.HasFormat( SotClipboardFormatId::SVIM ) )
618  {
619 
620  ImageMap aImageMap;
621 
622  // according to KA we don't need a BaseURL here
623  if( aDataHelper.GetImageMap( SotClipboardFormatId::SVIM, aImageMap ) )
624  {
625  SvxGalleryDrawModel aModel;
626 
627  if( aModel.GetModel() )
628  {
629  SdrPage* pPage = aModel.GetModel()->GetPage(0);
630  SdrGrafObj* pGrafObj = new SdrGrafObj(*aModel.GetModel(), *pGraphic );
631 
632  pGrafObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new SgaIMapInfo( aImageMap )) );
633  pPage->InsertObject( pGrafObj );
634  bRet = InsertModel( *aModel.GetModel(), nInsertPos );
635  }
636  }
637  }
638 
639  if( !bRet )
640  bRet = InsertGraphic( *pGraphic, nInsertPos );
641  }
642  }
643 
644  return bRet;
645 }
646 
647 void GalleryTheme::CopyToClipboard(sal_uInt32 nPos)
648 {
649  GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
650  pTransferable->CopyToClipboard(GetSystemClipboard());
651 }
652 
654 {
655  const INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
656  const INetURLObject aRelURL2( GetParent()->GetUserURL() );
657  sal_uInt32 nCount = GetObjectCount();
658  bool bRel;
659 
660  rOStm.WriteUInt16( 0x0004 );
661  write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, pThm->GetThemeName(), RTL_TEXTENCODING_UTF8);
662  rOStm.WriteUInt32( nCount ).WriteUInt16( osl_getThreadTextEncoding() );
663 
664  for( sal_uInt32 i = 0; i < nCount; i++ )
665  {
667  OUString aPath;
668 
669  if( SgaObjKind::SvDraw == pObj->eObjKind )
670  {
671  aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
672  bRel = false;
673  }
674  else
675  {
677  aPath = aPath.copy( 0, std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
678  bRel = aPath == aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE );
679 
680  if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) )
681  {
683  aPath = aPath.copy( std::min(aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
684  }
685  else
686  {
688  aPath = aPath.copy( 0, std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
689  bRel = aPath == aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE );
690 
691  if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength() + 1 ) ) )
692  {
694  aPath = aPath.copy( std::min(aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE ).getLength(), aPath.getLength()) );
695  }
696  else
698  }
699  }
700 
701  if ( !m_aDestDir.isEmpty() )
702  {
703  bool aFound = aPath.indexOf(m_aDestDir) != -1;
704  aPath = aPath.replaceFirst(m_aDestDir, "");
705  if ( aFound )
706  bRel = m_bDestDirRelative;
707  else
708  SAL_WARN( "svx", "failed to replace destdir of '"
709  << m_aDestDir << "' in '" << aPath << "'");
710  }
711 
712  rOStm.WriteBool( bRel );
713  write_uInt16_lenPrefixed_uInt8s_FromOUString(rOStm, aPath, RTL_TEXTENCODING_UTF8);
714  rOStm.WriteUInt32( pObj->nOffset ).WriteUInt16( static_cast<sal_uInt16>(pObj->eObjKind) );
715  }
716 
717  // more recently, a 512-byte reserve buffer is written,
718  // to recognize them two sal_uInt32-Ids will be written.
719  rOStm.WriteUInt32( COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) ).WriteUInt32( COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) );
720 
721  const long nReservePos = rOStm.Tell();
722  std::unique_ptr<VersionCompat> pCompat(new VersionCompat( rOStm, StreamMode::WRITE, 2 ));
723 
724  rOStm.WriteUInt32( GetId() ).WriteBool( pThm->IsNameFromResource() ); // From version 2 and up
725 
726  pCompat.reset();
727 
728  // Fill the rest of the buffer.
729  const long nRest = std::max( 512L - ( static_cast<long>(rOStm.Tell()) - nReservePos ), 0L );
730 
731  if( nRest )
732  {
733  std::unique_ptr<char[]> pReserve(new char[ nRest ]);
734  memset( pReserve.get(), 0, nRest );
735  rOStm.WriteBytes(pReserve.get(), nRest);
736  }
737 
738  return rOStm;
739 }
740 
742 {
743  sal_uInt32 nCount;
744  sal_uInt16 nVersion;
745 
746  rIStm.ReadUInt16( nVersion );
748  rIStm.ReadUInt32( nCount );
749 
750  if( nVersion >= 0x0004 )
751  {
752  sal_uInt16 nTmp16;
753  rIStm.ReadUInt16( nTmp16 );
754  }
755 
756  if( nCount <= ( 1 << 14 ) )
757  {
758  INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
759  INetURLObject aRelURL2( GetParent()->GetUserURL() );
760  sal_uInt32 nId1, nId2;
761  bool bRel;
762 
764  {
765  GalleryObject* pObj = i.get();
767  i.reset();
768  }
770 
771  for( sal_uInt32 i = 0; i < nCount; i++ )
772  {
773  std::unique_ptr<GalleryObject> pObj(new GalleryObject);
774 
775  OUString aFileName;
776  OUString aPath;
777  sal_uInt16 nTemp;
778 
779  rIStm.ReadCharAsBool( bRel );
780  OString aTempFileName = read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm);
781  rIStm.ReadUInt32( pObj->nOffset );
782  rIStm.ReadUInt16( nTemp ); pObj->eObjKind = static_cast<SgaObjKind>(nTemp);
783 
784  aFileName = OStringToOUString(aTempFileName, osl_getThreadTextEncoding());
785 
786  if( bRel )
787  {
788  aFileName = aFileName.replaceAll( "\\", "/" );
790 
791  if( aFileName[ 0 ] != '/' )
792  aPath += "/";
793 
794  aPath += aFileName;
795 
796  pObj->aURL = INetURLObject( aPath );
797 
798  if( !FileExists( pObj->aURL ) )
799  {
801 
802  if( aFileName[0] != '/' )
803  aPath += "/";
804 
805  aPath += aFileName;
806 
807  // assign this URL, even in the case it is not valid (#94482)
808  pObj->aURL = INetURLObject( aPath );
809  }
810  }
811  else
812  {
813  if( SgaObjKind::SvDraw == pObj->eObjKind )
814  {
815  OUString aDummyURL = "gallery/svdraw/" + aFileName;
816  pObj->aURL = INetURLObject( aDummyURL, INetProtocol::PrivSoffice );
817  }
818  else
819  {
820  OUString aLocalURL;
821 
822  pObj->aURL = INetURLObject( aFileName );
823 
824  if( ( pObj->aURL.GetProtocol() == INetProtocol::NotValid ) &&
825  osl::FileBase::getFileURLFromSystemPath( aFileName, aLocalURL ) == osl::FileBase::E_None )
826  {
827  pObj->aURL = INetURLObject( aLocalURL );
828  }
829  }
830  }
831  maGalleryObjectCollection.getObjectList().push_back( std::move(pObj) );
832  }
833 
834  rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 );
835 
836  // In newer versions a 512 byte reserve buffer is located at the end,
837  // the data is located at the beginning of this buffer and are clamped
838  // by a VersionCompat.
839  if( !rIStm.eof() &&
840  nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
841  nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
842  {
843  VersionCompat aCompat( rIStm, StreamMode::READ );
844  sal_uInt32 nTemp32;
845  bool bThemeNameFromResource = false;
846 
847  rIStm.ReadUInt32( nTemp32 );
848 
849  if( aCompat.GetVersion() >= 2 )
850  {
851  rIStm.ReadCharAsBool( bThemeNameFromResource );
852  }
853 
854  SetId( nTemp32, bThemeNameFromResource );
855  }
856  }
857  else
858  rIStm.SetError( SVSTREAM_READ_ERROR );
859 
860  ImplSetModified( false );
861 
862  return rIStm;
863 }
864 
866 {
867  return rTheme.ReadData( rIn );
868 }
869 
870 void GalleryTheme::ImplSetModified( bool bModified )
871 {
872  pThm->SetModified(bModified);
873 }
874 
879 sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
880 void GalleryTheme::SetId( sal_uInt32 nNewId, bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
881 bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
882 bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
883 
884 const OUString& GalleryTheme::GetName() const { return pThm->GetThemeName(); }
885 
886 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvStream & WriteBool(bool b)
bool GetGraphic(SotClipboardFormatId nFormat, Graphic &rGraphic)
URL aURL
bool InsertObject(const SgaObject &rObj, sal_uInt32 nPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:131
void Update(sal_Int32 nVal, sal_Int32 nMaxVal)
Definition: galmisc.cxx:350
const INetURLObject & GetStrURL() const
Definition: gallery1.hxx:67
bool IsModified() const
Definition: gallery1.hxx:74
bool IsDefault() const
Definition: galtheme.cxx:882
sal_uInt32 GetId() const
Definition: galtheme.cxx:879
bool InsertGraphic(const Graphic &rGraphic, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:400
SvStream & WriteUInt16(sal_uInt16 nUInt16)
bool CreateIMapGraphic(const FmFormModel &rModel, Graphic &rGraphic, ImageMap &rImageMap)
Definition: galmisc.cxx:120
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
sal_uInt32 mnBroadcasterLockCount
Definition: galtheme.hxx:84
SAL_DLLPRIVATE Gallery * GetParent() const
Definition: galtheme.hxx:145
sal_uInt32 mnThemeLockCount
Definition: galtheme.hxx:83
std::vector< std::unique_ptr< GalleryObject > > & getObjectList()
const INetURLObject & GetSdgURL() const
Definition: galtheme.cxx:876
#define SVSTREAM_READ_ERROR
SAL_DLLPRIVATE SvStream & WriteData(SvStream &rOut) const
Definition: galtheme.cxx:653
SAL_DLLPRIVATE bool InsertModelStream(const tools::SvRef< SotStorageStream > &rModelStream, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:488
SvStream & ReadCharAsBool(bool &rBool)
sal_Int64 n
OUString maPath
Definition: galtheme.hxx:50
void RemoveObject(sal_uInt32 nPos)
Definition: galtheme.cxx:180
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:170
FmFormModel * GetModel() const
bool IsReadOnly() const
Definition: gallery1.hxx:69
bool bReadOnly
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
Definition: svdpage.cxx:343
EmbeddedObjectRef * pObject
bool HasFormat(SotClipboardFormatId nFormat) const
void Clear()
OString read_uInt16_lenPrefixed_uInt8s_ToOString(SvStream &rStrm)
SAL_DLLPRIVATE bool GetURL(sal_uInt32 nPos, INetURLObject &rURL)
Definition: galtheme.cxx:499
SvStream & ReadGalleryTheme(SvStream &rIn, GalleryTheme &rTheme)
Definition: galtheme.cxx:865
bool eof() const
SgaObjKind eObjKind
Definition: galtheme.hxx:43
INetURLObject ImplGetURL(const GalleryObject *pObject)
Definition: galmisc.cxx:554
int nCount
GalleryThemeEntry * pThm
Definition: galtheme.hxx:82
INetURLObject aURL
Definition: galtheme.hxx:41
std::unique_ptr< GalleryObject > & get(sal_uInt32 nPos)
SvStream & WriteUInt32(sal_uInt32 nUInt32)
SAL_DLLPRIVATE SvStream & ReadData(SvStream &rIn)
Definition: galtheme.cxx:741
BitmapEx maPreviewBitmapEx
Definition: galtheme.hxx:47
SotClipboardFormatId
SAL_DLLPRIVATE const INetURLObject & GetStrURL() const
Definition: galtheme.cxx:878
virtual SAL_DLLPRIVATE ~GalleryTheme() override
Definition: galtheme.cxx:76
SAL_DLLPRIVATE void LockBroadcaster()
Definition: galtheme.hxx:132
bool IsAnimated() const
bool m_bDestDirRelative
Definition: galtheme.hxx:80
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
SgaObjKind
Definition: galmisc.hxx:55
sal_uInt32 GetId() const
Definition: gallery1.hxx:80
SAL_DLLPRIVATE bool InsertFileOrDirURL(const INetURLObject &rFileOrDirURL, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:538
#define DBG_ASSERT(sCon, aError)
int i
OUString m_aDestDir
Definition: galtheme.hxx:79
GalleryGraphicImportRet GalleryGraphicImport(const INetURLObject &rURL, Graphic &rGraphic, OUString &rFilterName)
Definition: galmisc.cxx:51
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:513
GraphicType GetType() const
static void insertFileOrDirURL(const INetURLObject &rFileOrDirURL, std::vector< INetURLObject > &rURLVector)
void SetModified(bool bSet)
Definition: gallery1.hxx:75
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:220
sal_uInt32 nOffset
Definition: galtheme.hxx:42
const GalleryStorageLocations & getGalleryStorageLocations() const
Definition: gallery1.hxx:60
bool GetString(SotClipboardFormatId nFormat, OUString &rStr)
ConvertDataFormat
void hideMarkHandles()
Definition: svdmrkv.cxx:577
SAL_DLLPRIVATE void GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx &rBitmapEx, Size &rSize, OUString &rTitle, OUString &rPath)
Definition: galtheme.cxx:160
bool ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
Definition: galtheme.cxx:199
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1904
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)
std::unique_ptr< GalleryBinaryEngine > mpGalleryBinaryEngine
Definition: galtheme.hxx:77
SAL_DLLPRIVATE bool InsertTransferable(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:550
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
Definition: galtheme.hxx:104
GalleryGraphicImportRet
Definition: galmisc.hxx:69
bool GetGraphic(sal_uInt32 nPos, Graphic &rGraphic)
Definition: galtheme.cxx:328
void CopyToClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard) const
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:288
size_t Count() const
void AppendFile(const OUString &rStr)
SAL_DLLPRIVATE bool IsBroadcasterLocked() const
Definition: galtheme.hxx:134
static bool isMediaURL(const OUString &rURL, const OUString &rReferer, bool bDeep=false, Size *pPreferredSizePixel=nullptr)
void UnlockBroadcaster()
Definition: galtheme.cxx:123
bool IsNameFromResource() const
Definition: gallery1.hxx:78
SAL_DLLPRIVATE void ImplBroadcast(sal_uInt32 nUpdatePos)
Definition: galtheme.cxx:97
void AppendUserData(std::unique_ptr< SdrObjUserData > pData)
Definition: svdobj.cxx:2620
bool GetSotStorageStream(SotClipboardFormatId nFormat, tools::SvRef< SotStorageStream > &rStreamRef)
bool GetImageMap(SotClipboardFormatId nFormat, ImageMap &rIMap)
GalleryObjectCollection maGalleryObjectCollection
Definition: galtheme.hxx:78
bool IsDefault() const
Definition: gallery1.cxx:729
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
SAL_DLLPRIVATE bool GetModelStream(sal_uInt32 nPos, tools::SvRef< SotStorageStream > const &rModelStreamRef)
Definition: galtheme.cxx:475
std::unique_ptr< GalleryBinaryEngine > createGalleryBinaryEngine(bool bReadOnly)
Definition: galtheme.cxx:91
bool GetModel(sal_uInt32 nPos, SdrModel &rModel)
Definition: galtheme.cxx:453
SAL_DLLPRIVATE void CopyToClipboard(sal_uInt32 nPos)
Definition: galtheme.cxx:647
static bool FileExists(const INetURLObject &rURL, const OUString &rExt)
void Broadcast(const SfxHint &rHint)
const GalleryObject * getForPosition(sal_uInt32 nPos) const
void SetId(sal_uInt32 nNewId, bool bResetThemeName)
Definition: gallery1.cxx:189
SAL_DLLPRIVATE bool GetThumb(sal_uInt32 nPos, BitmapEx &rBmp)
Definition: galtheme.cxx:314
bool GetFileList(SotClipboardFormatId nFormat, FileList &rFileList)
sal_uInt64 Tell() const
SAL_DLLPRIVATE GalleryTheme(Gallery *pGallery, GalleryThemeEntry *pThemeEntry)
Definition: galtheme.cxx:63
SAL_DLLPRIVATE const INetURLObject & GetThmURL() const
Definition: galtheme.cxx:875
bool bAbortActualize
Definition: galtheme.hxx:87
SAL_DLLPRIVATE void ImplSetModified(bool bModified)
Definition: galtheme.cxx:870
SAL_DLLPRIVATE void SetId(sal_uInt32 nNewId, bool bResetThemeName)
Definition: galtheme.cxx:880
#define SAL_WARN(area, stream)
OUString GetSvDrawStreamNameFromURL(const INetURLObject &rSvDrawObjURL)
Definition: galmisc.cxx:186
const OUString & GetName() const
Definition: galtheme.cxx:884
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:365
SAL_DLLPRIVATE bool UnlockTheme()
Definition: galtheme.cxx:108
bool IsReadOnly() const
Definition: galtheme.cxx:881
std::size_t write_uInt16_lenPrefixed_uInt8s_FromOUString(SvStream &rStrm, const OUString &rStr, rtl_TextEncoding eEnc)
OUString maTitle
Definition: galtheme.hxx:49
bool InsertModel(const FmFormModel &rModel, sal_uInt32 nInsertPos)
Definition: galtheme.cxx:466
const INetURLObject & GetSdvURL() const
Definition: gallery1.hxx:66
const OUString & GetThemeName() const
Definition: gallery1.hxx:62
const INetURLObject & GetSdgURL() const
Definition: gallery1.hxx:65
SAL_DLLPRIVATE const INetURLObject & GetSdvURL() const
Definition: galtheme.cxx:877
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
Definition: galtheme.cxx:155
const INetURLObject & GetThmURL() const
Definition: gallery1.hxx:64