Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/gallery2/galtheme.cxx
Line
Count
Source
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
24
#include <algorithm>
25
26
#include <osl/file.hxx>
27
#include <osl/thread.hxx>
28
#include <tools/urlobj.hxx>
29
#include <tools/vcompat.hxx>
30
#include <tools/datetime.hxx>
31
#include <sot/storage.hxx>
32
#include <sot/formats.hxx>
33
#include <sot/filelist.hxx>
34
#include <vcl/virdev.hxx>
35
#include <vcl/weld.hxx>
36
#include <avmedia/mediawindow.hxx>
37
#include <svx/svdograf.hxx>
38
#include <svx/fmmodel.hxx>
39
#include <svx/fmview.hxx>
40
#include <svx/galmisc.hxx>
41
#include <svx/galtheme.hxx>
42
#include <svx/svdpage.hxx>
43
#include <svx/galleryobjectcollection.hxx>
44
#include <galleryfilestorage.hxx>
45
#include <galobj.hxx>
46
#include <svx/gallery1.hxx>
47
#include "gallerydrawmodel.hxx"
48
#include <memory>
49
50
using namespace ::com::sun::star;
51
52
GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry )
53
0
    : mpParent(pGallery)
54
0
    , mpThm(pThemeEntry)
55
0
    , mnThemeLockCount(0)
56
0
    , mnBroadcasterLockCount(0)
57
0
    , mnDragPos(0)
58
0
    , mbDragging(false)
59
0
    , mbAbortActualize(false)
60
0
{
61
0
    mpGalleryStorageEngine = mpThm->createGalleryStorageEngine(maGalleryObjectCollection);
62
0
}
63
64
GalleryTheme::~GalleryTheme()
65
0
{
66
0
    if(mpThm->IsModified())
67
0
        if(!mpGalleryStorageEngine->implWrite(*this, mpThm))
68
0
            ImplSetModified(false);
69
70
0
    for (auto & pEntry : maGalleryObjectCollection.getObjectList())
71
0
    {
72
0
        Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
73
0
        pEntry.reset();
74
0
    }
75
0
    maGalleryObjectCollection.clear();
76
0
    mpGalleryStorageEngine->clearSotStorage();
77
0
}
78
79
void GalleryTheme::SetDestDir(const OUString& rDestDir, bool bRelative)
80
0
{
81
0
    mpGalleryStorageEngine->setDestDir(rDestDir, bRelative);
82
0
}
83
84
void GalleryTheme::ImplBroadcast(sal_uInt32 nUpdatePos)
85
0
{
86
0
    if( !IsBroadcasterLocked() )
87
0
    {
88
0
        if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
89
0
            nUpdatePos = GetObjectCount() - 1;
90
91
0
        Broadcast( GalleryHint( GalleryHintType::THEME_UPDATEVIEW, GetName(), reinterpret_cast<void*>(static_cast<sal_uIntPtr>(nUpdatePos)) ) );
92
0
    }
93
0
}
94
95
bool GalleryTheme::UnlockTheme()
96
0
{
97
0
    DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
98
99
0
    bool bRet = false;
100
101
0
    if( mnThemeLockCount )
102
0
    {
103
0
        --mnThemeLockCount;
104
0
        bRet = true;
105
0
    }
106
107
0
    return bRet;
108
0
}
109
110
void GalleryTheme::UnlockBroadcaster()
111
0
{
112
0
    DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
113
114
0
    if( mnBroadcasterLockCount && !--mnBroadcasterLockCount )
115
0
        ImplBroadcast( 0 );
116
0
}
117
118
bool GalleryTheme::InsertObject(const SgaObject& rObj, sal_uInt32 nInsertPos)
119
0
{
120
0
    if (!rObj.IsValid())
121
0
        return false;
122
123
0
    GalleryObject* pFoundEntry = nullptr;
124
0
    sal_uInt32 iFoundPos = 0;
125
0
    for (sal_uInt32 n = maGalleryObjectCollection.size(); iFoundPos < n; ++iFoundPos)
126
0
    {
127
0
        if (*maGalleryObjectCollection.get(iFoundPos)->m_oStorageUrl == rObj.GetURL())
128
0
        {
129
0
            pFoundEntry = maGalleryObjectCollection.get(iFoundPos).get();
130
0
            break;
131
0
        }
132
0
    }
133
134
0
    mpGalleryStorageEngine->insertObject(rObj, pFoundEntry, nInsertPos);
135
136
0
    ImplSetModified(true);
137
0
    Broadcast( GalleryHint( GalleryHintType::ADD_OBJECT, GetName(),
138
0
        reinterpret_cast<void*>(static_cast<sal_uIntPtr>(pFoundEntry? iFoundPos: nInsertPos)) ) );
139
140
0
    return true;
141
0
}
142
143
std::unique_ptr<SgaObject> GalleryTheme::AcquireObject(sal_uInt32 nPos)
144
0
{
145
0
    return mpGalleryStorageEngine->implReadSgaObject(maGalleryObjectCollection.getForPosition(nPos));
146
0
}
147
148
void GalleryTheme::GetPreviewBitmapAndStrings(sal_uInt32 nPos, Bitmap& rBitmap, Size& rSize, OUString& rTitle, OUString& rPath)
149
0
{
150
0
    const GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get();
151
152
0
    rBitmap = pGalleryObject->maPreviewBitmap;
153
0
    rSize = pGalleryObject->maPreparedSize;
154
0
    rTitle = pGalleryObject->maTitle;
155
0
    rPath = pGalleryObject->maPath;
156
0
}
157
158
void GalleryTheme::SetPreviewBitmapAndStrings(sal_uInt32 nPos, const Bitmap& rBitmap, const Size& rSize, const OUString& rTitle, const OUString& rPath)
159
0
{
160
0
    GalleryObject* pGalleryObject = maGalleryObjectCollection.get(nPos).get();
161
162
0
    pGalleryObject->maPreviewBitmap = rBitmap;
163
0
    pGalleryObject->maPreparedSize = rSize;
164
0
    pGalleryObject->maTitle = rTitle;
165
0
    pGalleryObject->maPath = rPath;
166
0
}
167
168
void GalleryTheme::RemoveObject(sal_uInt32 nPos)
169
0
{
170
0
    auto it = maGalleryObjectCollection.getObjectList().begin() + nPos;
171
0
    std::unique_ptr<GalleryObject> pEntry = std::move(*it);
172
0
    maGalleryObjectCollection.getObjectList().erase( it );
173
174
0
    mpGalleryStorageEngine->removeObject(pEntry);
175
176
0
    Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pEntry.get() ) );
177
0
    pEntry.reset();
178
179
0
    ImplSetModified( true );
180
0
    ImplBroadcast( nPos );
181
0
}
182
183
bool GalleryTheme::ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
184
0
{
185
0
    if (nOldPos == nNewPos || nOldPos >= maGalleryObjectCollection.size())
186
0
        return false;
187
188
0
    std::unique_ptr<GalleryObject> pEntry = std::move(maGalleryObjectCollection.get(nOldPos));
189
190
0
    maGalleryObjectCollection.getObjectList().insert(maGalleryObjectCollection.getObjectList().begin() + nNewPos, std::move(pEntry));
191
192
0
    if (nNewPos < nOldPos)
193
0
        nOldPos++;
194
195
0
    auto it = maGalleryObjectCollection.getObjectList().begin() + nOldPos;
196
0
    maGalleryObjectCollection.getObjectList().erase(it);
197
198
0
    ImplSetModified(true);
199
0
    ImplBroadcast((nNewPos < nOldPos)? nNewPos: (nNewPos - 1));
200
201
0
    return true;
202
0
}
203
204
void GalleryTheme::Actualize( const Link<const INetURLObject&, void>& rActualizeLink, GalleryProgress* pProgress )
205
0
{
206
0
    if( IsReadOnly() )
207
0
        return;
208
209
0
    Graphic         aGraphic;
210
0
    OUString        aFormat;
211
0
    const sal_uInt32 nCount = maGalleryObjectCollection.size();
212
213
0
    LockBroadcaster();
214
0
    mbAbortActualize = false;
215
216
    // reset delete flag
217
0
    for (sal_uInt32 i = 0; i < nCount; i++)
218
0
        maGalleryObjectCollection.get(i)->mbDelete = false;
219
220
0
    for (sal_uInt32 i = 0; ( i < nCount ) && !mbAbortActualize; i++)
221
0
    {
222
0
        if( pProgress )
223
0
            pProgress->Update( i, nCount - 1 );
224
225
0
        GalleryObject* pEntry = maGalleryObjectCollection.get(i).get();
226
227
0
        const INetURLObject aURL( *pEntry->m_oStorageUrl );
228
229
0
        rActualizeLink.Call( aURL );
230
231
        // SvDraw objects will be updated later
232
0
        if( pEntry->eObjKind != SgaObjKind::SvDraw )
233
0
        {
234
            // Still a function should be implemented,
235
            // which assigns files to the relevant entry.
236
            // insert graphics as graphic objects into the gallery
237
0
            if( pEntry->eObjKind == SgaObjKind::Sound )
238
0
            {
239
0
                SgaObjectSound aObjSound( aURL );
240
0
                if( !InsertObject( aObjSound ) )
241
0
                    pEntry->mbDelete = true;
242
0
            }
243
0
            else
244
0
            {
245
0
                aGraphic.Clear();
246
247
0
                if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) != GalleryGraphicImportRet::IMPORT_NONE )
248
0
                {
249
0
                    std::unique_ptr<SgaObject> pNewObj;
250
251
0
                    if ( SgaObjKind::Inet == pEntry->eObjKind )
252
0
                        pNewObj.reset(new SgaObjectINet( aGraphic, aURL ));
253
0
                    else if ( aGraphic.IsAnimated() )
254
0
                        pNewObj.reset(new SgaObjectAnim( aGraphic, aURL ));
255
0
                    else
256
0
                        pNewObj.reset(new SgaObjectBmp( aGraphic, aURL ));
257
258
0
                    if( !InsertObject( *pNewObj ) )
259
0
                        pEntry->mbDelete = true;
260
0
                }
261
0
                else
262
0
                    pEntry->mbDelete = true; // set delete flag
263
0
            }
264
0
        }
265
0
        else
266
0
        {
267
            //update SvDraw object
268
0
            if ( mpGalleryStorageEngine->GetSvDrawStorage().is() )
269
0
            {
270
0
                SgaObjectSvDraw aNewObj = mpGalleryStorageEngine->updateSvDrawObject(pEntry);
271
0
                if (aNewObj.IsValid() && !InsertObject(aNewObj))
272
0
                    pEntry->mbDelete = true;
273
0
            }
274
0
        }
275
0
    }
276
277
    // remove all entries with set flag
278
0
    for ( auto it = maGalleryObjectCollection.getObjectList().begin(); it != maGalleryObjectCollection.getObjectList().end(); /* increment is in the body of loop */)
279
0
    {
280
0
        if( (*it)->mbDelete )
281
0
        {
282
0
            Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), it->get() ) );
283
0
            it = maGalleryObjectCollection.getObjectList().erase( it );
284
0
        }
285
0
        else
286
0
            ++it;
287
0
    }
288
289
    // update theme
290
0
    mpGalleryStorageEngine->updateTheme();
291
0
    ImplSetModified( true );
292
0
    if (mpThm->IsModified())
293
0
        if (!mpGalleryStorageEngine->implWrite(*this, mpThm))
294
0
            ImplSetModified(false);
295
0
    UnlockBroadcaster();
296
0
}
297
298
bool GalleryTheme::GetThumb(sal_uInt32 nPos, Bitmap& rBmp)
299
0
{
300
0
    std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
301
0
    bool        bRet = false;
302
303
0
    if( pObj )
304
0
    {
305
0
        rBmp = pObj->GetThumbBmp();
306
0
        bRet = true;
307
0
    }
308
309
0
    return bRet;
310
0
}
311
312
bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
313
0
{
314
0
    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
315
0
    bool                    bRet = false;
316
317
0
    if( pObject )
318
0
    {
319
0
        const INetURLObject aURL( ImplGetURL( pObject ) );
320
321
0
        switch( pObject->eObjKind )
322
0
        {
323
0
            case SgaObjKind::Bitmap:
324
0
            case SgaObjKind::Animation:
325
0
            case SgaObjKind::Inet:
326
0
            {
327
0
                OUString aFilterDummy;
328
0
                bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy ) != GalleryGraphicImportRet::IMPORT_NONE );
329
0
            }
330
0
            break;
331
332
0
            case SgaObjKind::SvDraw:
333
0
            {
334
0
                SvxGalleryDrawModel aModel;
335
336
0
                if( aModel.GetModel() )
337
0
                {
338
0
                    if( GetModel( nPos, *aModel.GetModel() ) )
339
0
                    {
340
0
                        ImageMap aIMap;
341
342
0
                        if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
343
0
                            bRet = true;
344
0
                        else
345
0
                        {
346
0
                            ScopedVclPtrInstance< VirtualDevice > pVDev;
347
0
                            pVDev->SetMapMode( MapMode( MapUnit::Map100thMM ) );
348
0
                            FmFormView aView(*aModel.GetModel(), pVDev);
349
350
0
                            aView.hideMarkHandles();
351
0
                            aView.ShowSdrPage(aView.GetModel().GetPage(0));
352
0
                            aView.MarkAll();
353
0
                            rGraphic = aView.GetAllMarkedGraphic();
354
0
                            bRet = true;
355
0
                        }
356
0
                    }
357
0
                }
358
0
            }
359
0
            break;
360
361
0
            case SgaObjKind::Sound:
362
0
            {
363
0
                std::unique_ptr<SgaObject> pObj = AcquireObject( nPos );
364
365
0
                if( pObj )
366
0
                {
367
0
                    rGraphic = pObj->GetThumbBmp();
368
                    //Bitmap aBmp( pObj->GetThumbBmp() );
369
                    //aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
370
                    //rGraphic = aBmp;
371
0
                    bRet = true;
372
0
                }
373
0
            }
374
0
            break;
375
376
0
            default:
377
0
            break;
378
0
        }
379
0
    }
380
381
0
    return bRet;
382
0
}
383
384
bool GalleryTheme::InsertGraphic(const Graphic& rGraphic, sal_uInt32 nInsertPos)
385
0
{
386
0
    bool bRet = false;
387
388
0
    if( rGraphic.GetType() != GraphicType::NONE )
389
0
    {
390
0
        ConvertDataFormat nExportFormat = ConvertDataFormat::Unknown;
391
0
        const GfxLink     aGfxLink( rGraphic.GetGfxLink() );
392
393
0
        if( aGfxLink.GetDataSize() )
394
0
        {
395
0
            switch( aGfxLink.GetType() )
396
0
            {
397
0
                case GfxLinkType::EpsBuffer: nExportFormat = ConvertDataFormat::SVM; break;
398
0
                case GfxLinkType::NativeGif: nExportFormat = ConvertDataFormat::GIF; break;
399
400
                // #i15508# added BMP type
401
                // could not find/trigger a call to this, but should do no harm
402
0
                case GfxLinkType::NativeBmp: nExportFormat = ConvertDataFormat::BMP; break;
403
404
0
                case GfxLinkType::NativeJpg: nExportFormat = ConvertDataFormat::JPG; break;
405
0
                case GfxLinkType::NativePng: nExportFormat = ConvertDataFormat::PNG; break;
406
0
                case GfxLinkType::NativeTif: nExportFormat = ConvertDataFormat::TIF; break;
407
0
                case GfxLinkType::NativeWmf: nExportFormat = ConvertDataFormat::WMF; break;
408
0
                case GfxLinkType::NativeMet: nExportFormat = ConvertDataFormat::MET; break;
409
0
                case GfxLinkType::NativePct: nExportFormat = ConvertDataFormat::PCT; break;
410
0
                case GfxLinkType::NativeSvg: nExportFormat = ConvertDataFormat::SVG; break;
411
0
                case GfxLinkType::NativeWebp: nExportFormat = ConvertDataFormat::WEBP; break;
412
0
                default:
413
0
                    break;
414
0
            }
415
0
        }
416
0
        else
417
0
        {
418
0
            if( rGraphic.GetType() == GraphicType::Bitmap )
419
0
            {
420
0
                if( rGraphic.IsAnimated() )
421
0
                    nExportFormat = ConvertDataFormat::GIF;
422
0
                else
423
0
                    nExportFormat = ConvertDataFormat::PNG;
424
0
            }
425
0
            else
426
0
                nExportFormat = ConvertDataFormat::SVM;
427
0
        }
428
429
0
        const SgaObjectBmp aObjBmp = mpGalleryStorageEngine->insertGraphic(rGraphic, aGfxLink, nExportFormat, GetParent()->GetUserURL());
430
431
0
        if (aObjBmp.IsValid())
432
0
            bRet = InsertObject(aObjBmp, nInsertPos);
433
0
    }
434
435
0
    return bRet;
436
0
}
437
438
bool GalleryTheme::GetModel(sal_uInt32 nPos, SdrModel& rModel)
439
0
{
440
0
    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
441
0
    bool                    bRet = false;
442
443
0
    if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
444
0
    {
445
0
        bRet = mpGalleryStorageEngine->readModel(pObject, rModel);
446
0
    }
447
448
0
    return bRet;
449
0
}
450
451
bool GalleryTheme::InsertModel(const FmFormModel& rModel, sal_uInt32 nInsertPos)
452
0
{
453
0
    bool bRet = false;
454
0
    SgaObjectSvDraw aObjSvDraw = mpGalleryStorageEngine->insertModel(rModel, GetParent()->GetUserURL());
455
0
    if(aObjSvDraw.IsValid())
456
0
        bRet = InsertObject( aObjSvDraw, nInsertPos );
457
0
    return bRet;
458
0
}
459
460
bool GalleryTheme::GetModelStream(sal_uInt32 nPos, SvStream& rModelStream)
461
0
{
462
0
    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
463
0
    bool                    bRet = false;
464
465
0
    if( pObject && ( SgaObjKind::SvDraw == pObject->eObjKind ) )
466
0
    {
467
0
        bRet = mpGalleryStorageEngine->readModelStream(pObject, rModelStream);
468
0
    }
469
470
0
    return bRet;
471
0
}
472
473
bool GalleryTheme::InsertModelStream(SvStream& rModelStream, sal_uInt32 nInsertPos)
474
0
{
475
0
    bool            bRet = false;
476
477
0
    const SgaObjectSvDraw aObjSvDraw = mpGalleryStorageEngine->insertModelStream(rModelStream, GetParent()->GetUserURL());
478
0
    if(aObjSvDraw.IsValid())
479
0
        bRet = InsertObject( aObjSvDraw, nInsertPos );
480
481
0
    return bRet;
482
0
}
483
484
bool GalleryTheme::GetURL(sal_uInt32 nPos, INetURLObject& rURL) const
485
0
{
486
0
    const GalleryObject*    pObject = maGalleryObjectCollection.getForPosition( nPos );
487
0
    bool                    bRet = false;
488
489
0
    if( pObject )
490
0
    {
491
0
        rURL = ImplGetURL( pObject );
492
0
        bRet = true;
493
0
    }
494
495
0
    return bRet;
496
0
}
497
498
bool GalleryTheme::InsertURL(const INetURLObject& rURL, sal_uInt32 nInsertPos)
499
0
{
500
0
    Graphic         aGraphic;
501
0
    OUString        aFormat;
502
0
    std::unique_ptr<SgaObject> pNewObj;
503
0
    const GalleryGraphicImportRet nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
504
0
    bool            bRet = false;
505
506
0
    if( nImportRet != GalleryGraphicImportRet::IMPORT_NONE )
507
0
    {
508
0
        if ( aGraphic.IsAnimated() )
509
0
            pNewObj.reset(new SgaObjectAnim( aGraphic, rURL ));
510
0
        else
511
0
            pNewObj.reset(new SgaObjectBmp( aGraphic, rURL ));
512
0
    }
513
0
#if HAVE_FEATURE_AVMEDIA
514
0
    else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ), u""_ustr/*TODO?*/ ) )
515
0
        pNewObj.reset(new SgaObjectSound( rURL ));
516
0
#endif
517
0
    if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
518
0
        bRet = true;
519
520
0
    return bRet;
521
0
}
522
523
bool GalleryTheme::InsertFileOrDirURL(const INetURLObject& rFileOrDirURL, sal_uInt32 nInsertPos)
524
0
{
525
0
    bool bRet = false;
526
0
    std::vector< INetURLObject > aURLVector;
527
0
    GalleryFileStorage::insertFileOrDirURL(rFileOrDirURL, aURLVector);
528
529
0
    for( const auto& rURL : aURLVector )
530
0
        bRet = bRet || InsertURL( rURL, nInsertPos );
531
532
0
    return bRet;
533
0
}
534
535
bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uInt32 nInsertPos)
536
0
{
537
0
    bool bRet = false;
538
539
0
    if( rxTransferable.is() )
540
0
    {
541
0
        TransferableDataHelper  aDataHelper( rxTransferable );
542
0
        std::optional<Graphic> oGraphic;
543
544
0
        if( aDataHelper.HasFormat( SotClipboardFormatId::DRAWING ) )
545
0
        {
546
0
            if (std::unique_ptr<SvStream> xModelStm = aDataHelper.GetSotStorageStream( SotClipboardFormatId::DRAWING ) )
547
0
                bRet = InsertModelStream( *xModelStm, nInsertPos );
548
0
        }
549
0
        else if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) ||
550
0
                 aDataHelper.HasFormat( SotClipboardFormatId::SIMPLE_FILE ) )
551
0
        {
552
0
            FileList aFileList;
553
554
0
            if( aDataHelper.HasFormat( SotClipboardFormatId::FILE_LIST ) )
555
0
                aDataHelper.GetFileList( SotClipboardFormatId::FILE_LIST, aFileList );
556
0
            else
557
0
            {
558
0
                OUString aFile;
559
0
                if (aDataHelper.GetString(SotClipboardFormatId::SIMPLE_FILE, aFile) && !aFile.isEmpty())
560
0
                    aFileList.AppendFile( aFile );
561
0
            }
562
563
0
            for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
564
0
            {
565
0
                const OUString  aFile( aFileList.GetFile( i ) );
566
0
                INetURLObject   aURL( aFile );
567
568
0
                if( aURL.GetProtocol() == INetProtocol::NotValid )
569
0
                {
570
0
                    OUString aLocalURL;
571
572
0
                    if( osl::FileBase::getFileURLFromSystemPath( aFile, aLocalURL ) == osl::FileBase::E_None )
573
0
                        aURL = INetURLObject( aLocalURL );
574
0
                }
575
576
0
                if( aURL.GetProtocol() != INetProtocol::NotValid )
577
0
                    bRet = InsertFileOrDirURL( aURL, nInsertPos );
578
0
            }
579
0
        }
580
0
        else
581
0
        {
582
0
            Graphic aGraphic;
583
0
            SotClipboardFormatId nFormat = SotClipboardFormatId::NONE;
584
585
0
            if( aDataHelper.HasFormat( SotClipboardFormatId::SVXB ) )
586
0
                nFormat = SotClipboardFormatId::SVXB;
587
0
            else if( aDataHelper.HasFormat( SotClipboardFormatId::GDIMETAFILE ) )
588
0
                nFormat = SotClipboardFormatId::GDIMETAFILE;
589
0
            else if( aDataHelper.HasFormat( SotClipboardFormatId::BITMAP ) )
590
0
                nFormat = SotClipboardFormatId::BITMAP;
591
592
0
            if( nFormat != SotClipboardFormatId::NONE && aDataHelper.GetGraphic( nFormat, aGraphic ) )
593
0
                oGraphic.emplace( aGraphic );
594
0
        }
595
596
0
        if( oGraphic )
597
0
        {
598
0
            bRet = false;
599
600
0
            if( aDataHelper.HasFormat( SotClipboardFormatId::SVIM ) )
601
0
            {
602
603
0
                ImageMap aImageMap;
604
605
                // according to KA we don't need a BaseURL here
606
0
                if( aDataHelper.GetImageMap( SotClipboardFormatId::SVIM, aImageMap ) )
607
0
                {
608
0
                    SvxGalleryDrawModel aModel;
609
610
0
                    if( aModel.GetModel() )
611
0
                    {
612
0
                        SdrPage*    pPage = aModel.GetModel()->GetPage(0);
613
0
                        rtl::Reference<SdrGrafObj> pGrafObj = new SdrGrafObj(*aModel.GetModel(), *oGraphic );
614
615
0
                        pGrafObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new SgaIMapInfo( aImageMap )) );
616
0
                        pPage->InsertObject( pGrafObj.get() );
617
0
                        bRet = InsertModel( *aModel.GetModel(), nInsertPos );
618
0
                    }
619
0
                }
620
0
            }
621
622
0
            if( !bRet )
623
0
                bRet = InsertGraphic( *oGraphic, nInsertPos );
624
0
        }
625
0
    }
626
627
0
    return bRet;
628
0
}
629
630
void GalleryTheme::CopyToClipboard(const weld::Widget& rWidget, sal_uInt32 nPos)
631
0
{
632
0
    rtl::Reference<GalleryTransferable> pTransferable = new GalleryTransferable( this, nPos, false );
633
0
    pTransferable->CopyToClipboard(rWidget.get_clipboard());
634
0
}
635
636
DateTime GalleryTheme::getModificationDate() const
637
0
{
638
0
    return mpGalleryStorageEngine->getModificationDate();
639
0
}
640
641
SvStream& GalleryTheme::ReadData( SvStream& rIStm )
642
0
{
643
0
    sal_uInt32          nCount;
644
0
    sal_uInt16          nVersion;
645
646
0
    rIStm.ReadUInt16( nVersion );
647
0
    read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm);
648
0
    rIStm.ReadUInt32( nCount );
649
650
0
    if( nVersion >= 0x0004 )
651
0
    {
652
0
        sal_uInt16 nTmp16;
653
0
        rIStm.ReadUInt16( nTmp16 );
654
0
    }
655
656
0
    if( nCount <= ( 1 << 14 ) )
657
0
    {
658
0
        INetURLObject   aRelURL1( GetParent()->GetRelativeURL() );
659
0
        INetURLObject   aRelURL2( GetParent()->GetUserURL() );
660
0
        sal_uInt32      nId1, nId2;
661
0
        bool            bRel;
662
663
0
        for(auto & i : maGalleryObjectCollection.getObjectList())
664
0
        {
665
0
            GalleryObject* pObj = i.get();
666
0
            Broadcast( GalleryHint( GalleryHintType::CLOSE_OBJECT, GetName(), pObj ) );
667
0
            i.reset();
668
0
        }
669
0
        maGalleryObjectCollection.clear();
670
671
0
        for( sal_uInt32 i = 0; i < nCount; i++ )
672
0
        {
673
0
            std::unique_ptr<GalleryObject> pObj(new GalleryObject);
674
675
0
            OUString    aFileName;
676
0
            sal_uInt16  nTemp;
677
678
0
            rIStm.ReadCharAsBool( bRel );
679
0
            OString aTempFileName = read_uInt16_lenPrefixed_uInt8s_ToOString(rIStm);
680
0
            rIStm.ReadUInt32( pObj->nOffset );
681
0
            rIStm.ReadUInt16( nTemp ); pObj->eObjKind = static_cast<SgaObjKind>(nTemp);
682
683
0
            aFileName = OStringToOUString(aTempFileName, osl_getThreadTextEncoding());
684
685
0
            pObj->m_oStorageUrl.emplace();
686
687
0
            if( bRel )
688
0
            {
689
0
                aFileName = aFileName.replaceAll( "\\", "/" );
690
0
                OUString aPath = aRelURL1.GetMainURL( INetURLObject::DecodeMechanism::NONE );
691
692
0
                if( aFileName[ 0 ] != '/' )
693
0
                        aPath += "/";
694
695
0
                aPath += aFileName;
696
697
0
                pObj->m_oStorageUrl = INetURLObject(aPath);
698
699
0
                if (!FileExists(*pObj->m_oStorageUrl))
700
0
                {
701
0
                    aPath = aRelURL2.GetMainURL( INetURLObject::DecodeMechanism::NONE );
702
703
0
                    if( aFileName[0] != '/' )
704
0
                        aPath += "/";
705
706
0
                    aPath += aFileName;
707
708
                    // assign this URL, even in the case it is not valid (#94482)
709
0
                    pObj->m_oStorageUrl = INetURLObject(aPath);
710
0
                }
711
0
            }
712
0
            else
713
0
            {
714
0
                if( SgaObjKind::SvDraw == pObj->eObjKind )
715
0
                {
716
0
                    OUString aDummyURL = "gallery/svdraw/" + aFileName;
717
0
                    pObj->m_oStorageUrl = INetURLObject(aDummyURL, INetProtocol::PrivSoffice);
718
0
                }
719
0
                else
720
0
                {
721
0
                    OUString aLocalURL;
722
723
0
                    pObj->m_oStorageUrl = INetURLObject(aFileName);
724
725
0
                    if( ( pObj->m_oStorageUrl->GetProtocol() == INetProtocol::NotValid ) &&
726
0
                        osl::FileBase::getFileURLFromSystemPath( aFileName, aLocalURL ) == osl::FileBase::E_None )
727
0
                    {
728
0
                        pObj->m_oStorageUrl = INetURLObject(aLocalURL);
729
0
                    }
730
0
                }
731
0
            }
732
0
            maGalleryObjectCollection.getObjectList().push_back( std::move(pObj) );
733
0
        }
734
735
0
        rIStm.ReadUInt32( nId1 ).ReadUInt32( nId2 );
736
737
        // In newer versions a 512 byte reserve buffer is located at the end,
738
        // the data is located at the beginning of this buffer and are clamped
739
        // by a VersionCompatRead.
740
0
        if( !rIStm.eof() &&
741
0
            nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
742
0
            nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
743
0
        {
744
0
            VersionCompatRead aCompat(rIStm);
745
0
            sal_uInt32      nTemp32;
746
0
            bool            bThemeNameFromResource = false;
747
748
0
            rIStm.ReadUInt32( nTemp32 );
749
750
0
            if( aCompat.GetVersion() >= 2 )
751
0
            {
752
0
                rIStm.ReadCharAsBool( bThemeNameFromResource );
753
0
            }
754
755
0
            SetId( nTemp32, bThemeNameFromResource );
756
0
        }
757
0
    }
758
0
    else
759
0
        rIStm.SetError( SVSTREAM_READ_ERROR );
760
761
0
    ImplSetModified( false );
762
763
0
    return rIStm;
764
0
}
765
766
void GalleryTheme::ImplSetModified( bool bModified )
767
0
{
768
0
    mpThm->SetModified(bModified);
769
0
}
770
771
0
sal_uInt32 GalleryTheme::GetId() const { return mpThm->GetId(); }
772
0
void GalleryTheme::SetId( sal_uInt32 nNewId, bool bResetThemeName ) { mpThm->SetId( nNewId, bResetThemeName ); }
773
0
bool GalleryTheme::IsReadOnly() const { return mpThm->IsReadOnly(); }
774
0
bool GalleryTheme::IsDefault() const { return mpThm->IsDefault(); }
775
776
0
const OUString& GalleryTheme::GetName() const { return mpThm->GetThemeName(); }
777
0
const INetURLObject& GalleryTheme::getThemeURL() const { return mpGalleryStorageEngine->getThemeURL(); }
778
779
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */