Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/unodraw/unomod.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 <sal/config.h>
21
22
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23
#include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
24
#include <com/sun/star/lang/NoSupportException.hpp>
25
#include <vcl/svapp.hxx>
26
#include <svl/itempool.hxx>
27
#include <svtools/unoevent.hxx>
28
#include <comphelper/sequence.hxx>
29
#include <o3tl/string_view.hxx>
30
#include <cppuhelper/supportsservice.hxx>
31
32
#include <cppuhelper/implbase.hxx>
33
#include <svx/unofill.hxx>
34
#include <editeng/unonrule.hxx>
35
#include <svtools/unoimap.hxx>
36
#include <sfx2/event.hxx>
37
#include <svx/fmmodel.hxx>
38
#include <svx/fmpage.hxx>
39
#include <svx/unoapi.hxx>
40
41
#include <svx/svdmodel.hxx>
42
#include <svx/unoprov.hxx>
43
#include <svx/unopage.hxx>
44
#include <editeng/unofield.hxx>
45
#include <svx/unomod.hxx>
46
#include <svx/unomodel.hxx>
47
#include <svx/svdobj.hxx>
48
#include <svx/svdpage.hxx>
49
#include <svx/SvxXTextColumns.hxx>
50
#include <svx/unoshape.hxx>
51
#include <xmloff/xmlgrhlp.hxx>
52
53
#include <com/sun/star/text/textfield/Type.hpp>
54
55
//-
56
57
using namespace ::com::sun::star;
58
59
//-
60
61
#define QUERYINT( xint ) \
62
0
    if( rType == cppu::UnoType<xint>::get() ) \
63
0
        aAny <<= uno::Reference< xint >(this)
64
65
//-
66
67
class SvxUnoDrawPagesAccess : public ::cppu::WeakImplHelper< css::drawing::XDrawPages, css::lang::XServiceInfo >
68
{
69
private:
70
    SvxUnoDrawingModel& mrModel;
71
72
public:
73
    explicit SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel ) noexcept;
74
75
    // XDrawPages
76
    virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL insertNewByIndex( sal_Int32 nIndex ) override;
77
    virtual void SAL_CALL remove( const css::uno::Reference< css::drawing::XDrawPage >& xPage ) override;
78
79
    // XIndexAccess
80
    virtual sal_Int32 SAL_CALL getCount() override ;
81
    virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
82
83
    // XElementAccess
84
    virtual css::uno::Type SAL_CALL getElementType() override;
85
    virtual sal_Bool SAL_CALL hasElements() override;
86
87
    // XServiceInfo
88
    virtual OUString SAL_CALL getImplementationName(  ) override;
89
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
90
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
91
};
92
//-
93
94
static const SvEventDescription* ImplGetSupportedMacroItems()
95
0
{
96
0
    static const SvEventDescription aMacroDescriptionsImpl[] =
97
0
    {
98
0
        { SvMacroItemId::OnMouseOver, "OnMouseOver" },
99
0
        { SvMacroItemId::OnMouseOut,  "OnMouseOut" },
100
0
        { SvMacroItemId::NONE, nullptr }
101
0
    };
102
103
0
    return aMacroDescriptionsImpl;
104
0
}
105
106
//-
107
108
/** fills the given EventObject from the given SdrHint.
109
    @returns
110
        true    if the SdrHint could be translated to an EventObject<br>
111
        false   if not
112
*/
113
bool SvxUnoDrawMSFactory::createEvent( const SdrModel* pDoc, const SdrHint* pSdrHint, css::document::EventObject& aEvent )
114
0
{
115
0
    const SdrObject* pObj = nullptr;
116
0
    const SdrPage* pPage = nullptr;
117
118
0
    switch( pSdrHint->GetKind() )
119
0
    {
120
//              case SdrHintKind::LayerChange:             // layer definition changed
121
//              case SdrHintKind::LayerOrderChange:        // layer order changed (Insert/Remove/ChangePos)
122
//              case HINT_LAYERSETCHG:          // layer set changed
123
//              case HINT_LAYERSETORDERCHG:     // layer set order changed (Insert/Remove/ChangePos)
124
125
//      case HINT_PAGECHG:              // page changed
126
//          aEvent.EventName = "PageModified";
127
//          pPage = pSdrHint->GetPage();
128
//          break;
129
0
        case SdrHintKind::PageOrderChange:         // draw or master page order changed (Insert/Remove/ChangePos)
130
0
            aEvent.EventName = "PageOrderModified";
131
0
            pPage = pSdrHint->GetPage();
132
0
            break;
133
0
        case SdrHintKind::ObjectChange:               // object changed
134
0
            aEvent.EventName = "ShapeModified";
135
0
            pObj = pSdrHint->GetObject();
136
0
            break;
137
0
        case SdrHintKind::ObjectInserted:          // add new draw object
138
0
            aEvent.EventName = "ShapeInserted";
139
0
            pObj = pSdrHint->GetObject();
140
0
            break;
141
0
        case SdrHintKind::ObjectRemoved:           // removed draw object from list
142
0
            aEvent.EventName = "ShapeRemoved";
143
0
            pObj = pSdrHint->GetObject();
144
0
            break;
145
//                SdrHintKind::DefaultTabChange,   // default tab width changed
146
//                SdrHintKind::SwitchToPage,    // #94278# UNDO/REDO at an object evtl. on another page
147
//                HINT_OBJLISTCLEAR     // Is called before an SdrObjList will be cleared
148
0
        default:
149
0
            return false;
150
0
    }
151
152
0
    if( pObj )
153
0
        aEvent.Source = const_cast<SdrObject*>(pObj)->getUnoShape();
154
0
    else if( pPage )
155
0
        aEvent.Source = const_cast<SdrPage*>(pPage)->getUnoPage();
156
0
    else
157
0
        aEvent.Source = const_cast<SdrModel*>(pDoc)->getUnoModel();
158
159
0
    return true;
160
0
}
161
162
namespace {
163
164
css::uno::Reference<css::uno::XInterface> create(
165
    OUString const & rServiceSpecifier, OUString const & referer)
166
66.9k
{
167
66.9k
    if( rServiceSpecifier.startsWith("com.sun.star.drawing.") )
168
39.3k
    {
169
39.3k
        std::optional<SdrObjKind> nType = UHashMap::getId( rServiceSpecifier );
170
39.3k
        if( nType )
171
39.3k
        {
172
39.3k
            SdrInventor nI = IsInventorE3D(*nType) ? SdrInventor::E3d : SdrInventor::Default;
173
174
39.3k
            return cppu::getXWeak(SvxDrawPage::CreateShapeByTypeAndInventor( *nType, nI, nullptr, nullptr, referer ).get());
175
39.3k
        }
176
39.3k
    }
177
27.5k
    else if (rServiceSpecifier == "com.sun.star.document.ImportGraphicStorageHandler")
178
0
    {
179
0
        return cppu::getXWeak( SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode::Read ).get() );
180
0
    }
181
27.5k
    else if (rServiceSpecifier == "com.sun.star.text.TextColumns")
182
18
    {
183
18
        return SvxXTextColumns_createInstance();
184
18
    }
185
186
27.5k
    uno::Reference< uno::XInterface > xRet( SvxUnoDrawMSFactory::createTextField( rServiceSpecifier ) );
187
27.5k
    if( !xRet.is() )
188
477
        throw lang::ServiceNotRegisteredException("unknown service: " + rServiceSpecifier);
189
190
27.0k
    return xRet;
191
27.5k
}
192
193
}
194
195
uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstance( const OUString& rServiceSpecifier )
196
66.8k
{
197
66.8k
    return create(rServiceSpecifier, u""_ustr);
198
66.8k
}
199
200
uno::Reference< uno::XInterface > SvxUnoDrawMSFactory::createTextField( std::u16string_view ServiceSpecifier )
201
27.5k
{
202
27.5k
    return SvxUnoTextCreateTextField( ServiceSpecifier );
203
27.5k
}
204
205
uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawMSFactory::createInstanceWithArguments( const OUString& ServiceSpecifier, const uno::Sequence< css::uno::Any >& Arguments )
206
182
{
207
182
    OUString arg;
208
182
    if ((ServiceSpecifier == "com.sun.star.drawing.GraphicObjectShape"
209
6
         || ServiceSpecifier == "com.sun.star.drawing.AppletShape"
210
6
         || ServiceSpecifier == "com.sun.star.drawing.FrameShape"
211
6
         || ServiceSpecifier == "com.sun.star.drawing.OLE2Shape"
212
0
         || ServiceSpecifier == "com.sun.star.drawing.MediaShape"
213
0
         || ServiceSpecifier == "com.sun.star.drawing.PluginShape")
214
182
        && Arguments.getLength() == 1 && (Arguments[0] >>= arg))
215
182
    {
216
182
        return create(ServiceSpecifier, arg);
217
182
    }
218
0
    throw lang::NoSupportException();
219
182
}
220
221
uno::Sequence< OUString > SAL_CALL SvxUnoDrawMSFactory::getAvailableServiceNames()
222
21.1k
{
223
21.1k
    return UHashMap::getServiceNames();
224
21.1k
}
225
226
SdrModel& SvxUnoDrawingModel::getSdrModelFromUnoModel() const
227
0
{
228
0
    OSL_ENSURE(mpDoc, "No SdrModel in UnoDrawingModel, should not happen");
229
0
    return *mpDoc;
230
0
}
231
232
SvxUnoDrawingModel::SvxUnoDrawingModel(SdrModel* pDoc) noexcept
233
0
:   SfxBaseModel(nullptr),
234
0
    mpDoc(pDoc)
235
0
{
236
0
}
237
238
SvxUnoDrawingModel::~SvxUnoDrawingModel() noexcept
239
0
{
240
0
}
241
242
uno::Any SAL_CALL SvxUnoDrawingModel::queryInterface( const uno::Type & rType )
243
0
{
244
0
    uno::Any aAny;
245
246
0
    QUERYINT(lang::XServiceInfo);
247
0
    else QUERYINT(lang::XMultiServiceFactory);
248
0
    else QUERYINT(drawing::XDrawPagesSupplier);
249
0
    else QUERYINT(css::ucb::XAnyCompareFactory);
250
0
    else
251
0
        return SfxBaseModel::queryInterface( rType );
252
253
0
    return aAny;
254
0
}
255
256
// XTypeProvider
257
uno::Sequence< uno::Type > SAL_CALL SvxUnoDrawingModel::getTypes(  )
258
0
{
259
0
    if( !maTypeSequence.hasElements() )
260
0
    {
261
0
        maTypeSequence = comphelper::concatSequences( SfxBaseModel::getTypes(),
262
0
            uno::Sequence {
263
0
                cppu::UnoType<lang::XServiceInfo>::get(),
264
0
                cppu::UnoType<lang::XMultiServiceFactory>::get(),
265
0
                cppu::UnoType<drawing::XDrawPagesSupplier>::get(),
266
0
                cppu::UnoType<css::ucb::XAnyCompareFactory>::get() });
267
0
    }
268
0
    return maTypeSequence;
269
0
}
270
271
uno::Sequence< sal_Int8 > SAL_CALL SvxUnoDrawingModel::getImplementationId(  )
272
0
{
273
0
    return css::uno::Sequence<sal_Int8>();
274
0
}
275
276
void SAL_CALL SvxUnoDrawingModel::lockControllers(  )
277
0
{
278
0
    if( mpDoc )
279
0
        mpDoc->setLock(true);
280
0
}
281
282
void SAL_CALL SvxUnoDrawingModel::unlockControllers(  )
283
0
{
284
0
    if( mpDoc && mpDoc->isLocked() )
285
0
    {
286
0
        mpDoc->setLock(false);
287
0
    }
288
0
}
289
290
sal_Bool SAL_CALL SvxUnoDrawingModel::hasControllersLocked(  )
291
0
{
292
0
    return mpDoc && mpDoc->isLocked();
293
0
}
294
295
// XDrawPagesSupplier
296
uno::Reference< drawing::XDrawPages > SAL_CALL SvxUnoDrawingModel::getDrawPages()
297
0
{
298
0
    ::SolarMutexGuard aGuard;
299
300
0
    rtl::Reference< SvxUnoDrawPagesAccess >  xDrawPages( mxDrawPagesAccess );
301
302
0
    if( !xDrawPages.is() )
303
0
    {
304
0
        xDrawPages = new SvxUnoDrawPagesAccess(*this);
305
0
        mxDrawPagesAccess = xDrawPages.get();
306
0
    }
307
308
0
    return xDrawPages;
309
0
}
310
311
// XMultiServiceFactory ( SvxFmMSFactory )
312
uno::Reference< uno::XInterface > SAL_CALL SvxUnoDrawingModel::createInstance( const OUString& aServiceSpecifier )
313
0
{
314
0
    ::SolarMutexGuard aGuard;
315
316
0
    if( aServiceSpecifier == "com.sun.star.drawing.DashTable" )
317
0
    {
318
0
        if( !mxDashTable.is() )
319
0
            mxDashTable = SvxUnoDashTable_createInstance( mpDoc );
320
0
        return mxDashTable;
321
0
    }
322
0
    if( aServiceSpecifier == "com.sun.star.drawing.GradientTable" )
323
0
    {
324
0
        if( !mxGradientTable.is() )
325
0
            mxGradientTable = SvxUnoGradientTable_createInstance( mpDoc );
326
0
        return mxGradientTable;
327
0
    }
328
0
    if( aServiceSpecifier == "com.sun.star.drawing.HatchTable" )
329
0
    {
330
0
        if( !mxHatchTable.is() )
331
0
            mxHatchTable = SvxUnoHatchTable_createInstance( mpDoc );
332
0
        return mxHatchTable;
333
0
    }
334
0
    if( aServiceSpecifier == "com.sun.star.drawing.BitmapTable" )
335
0
    {
336
0
        if( !mxBitmapTable.is() )
337
0
            mxBitmapTable = SvxUnoBitmapTable_createInstance( mpDoc );
338
0
        return mxBitmapTable;
339
0
    }
340
0
    if( aServiceSpecifier == "com.sun.star.drawing.TransparencyGradientTable" )
341
0
    {
342
0
        if( !mxTransGradientTable.is() )
343
0
            mxTransGradientTable = SvxUnoTransGradientTable_createInstance( mpDoc );
344
0
        return mxTransGradientTable;
345
0
    }
346
0
    if( aServiceSpecifier == "com.sun.star.drawing.MarkerTable" )
347
0
    {
348
0
        if( !mxMarkerTable.is() )
349
0
            mxMarkerTable = SvxUnoMarkerTable_createInstance( mpDoc );
350
0
        return mxMarkerTable;
351
0
    }
352
0
    if( aServiceSpecifier == "com.sun.star.text.NumberingRules" )
353
0
    {
354
0
        return uno::Reference< uno::XInterface >( SvxCreateNumRule( mpDoc ), uno::UNO_QUERY );
355
0
    }
356
357
0
    if ( aServiceSpecifier == "com.sun.star.image.ImageMapRectangleObject" )
358
0
    {
359
0
        return SvUnoImageMapRectangleObject_createInstance( ImplGetSupportedMacroItems() );
360
0
    }
361
362
0
    if ( aServiceSpecifier == "com.sun.star.image.ImageMapCircleObject" )
363
0
    {
364
0
        return SvUnoImageMapCircleObject_createInstance( ImplGetSupportedMacroItems() );
365
0
    }
366
367
0
    if ( aServiceSpecifier == "com.sun.star.image.ImageMapPolygonObject" )
368
0
    {
369
0
        return SvUnoImageMapPolygonObject_createInstance( ImplGetSupportedMacroItems() );
370
0
    }
371
372
0
    if( aServiceSpecifier == "com.sun.star.text.TextField.DateTime" )
373
0
    {
374
0
        return cppu::getXWeak(new SvxUnoTextField(text::textfield::Type::DATE));
375
0
    }
376
377
0
    uno::Reference< uno::XInterface > xRet;
378
379
0
    static constexpr OUString aPackagePrefix( u"com.sun.star.presentation."_ustr );
380
0
    if( aServiceSpecifier.startsWith( aPackagePrefix ) )
381
0
    {
382
0
        SvxShape* pShape = nullptr;
383
384
0
        SdrObjKind nType = SdrObjKind::Text;
385
0
        std::u16string_view aTypeName = aServiceSpecifier.subView( aPackagePrefix.getLength() );
386
        // create a shape wrapper
387
0
        if( o3tl::starts_with(aTypeName, u"TitleTextShape") )
388
0
        {
389
0
            nType = SdrObjKind::Text;
390
0
        }
391
0
        else if( o3tl::starts_with(aTypeName, u"OutlinerShape" ) )
392
0
        {
393
0
            nType = SdrObjKind::Text;
394
0
        }
395
0
        else if( o3tl::starts_with(aTypeName, u"SubtitleShape" ) )
396
0
        {
397
0
            nType = SdrObjKind::Text;
398
0
        }
399
0
        else if( o3tl::starts_with(aTypeName, u"GraphicObjectShape" ) )
400
0
        {
401
0
            nType = SdrObjKind::Graphic;
402
0
        }
403
0
        else if( o3tl::starts_with(aTypeName, u"PageShape" ) )
404
0
        {
405
0
            nType = SdrObjKind::Page;
406
0
        }
407
0
        else if( o3tl::starts_with(aTypeName, u"OLE2Shape" ) )
408
0
        {
409
0
            nType = SdrObjKind::OLE2;
410
0
        }
411
0
        else if( o3tl::starts_with(aTypeName, u"ChartShape" ) )
412
0
        {
413
0
            nType = SdrObjKind::OLE2;
414
0
        }
415
0
        else if( o3tl::starts_with(aTypeName, u"OrgChartShape" ) )
416
0
        {
417
0
            nType = SdrObjKind::OLE2;
418
0
        }
419
0
        else if( o3tl::starts_with(aTypeName, u"NotesShape" ) )
420
0
        {
421
0
            nType = SdrObjKind::Text;
422
0
        }
423
0
        else if( o3tl::starts_with(aTypeName, u"HandoutShape" ) )
424
0
        {
425
0
            nType = SdrObjKind::Page;
426
0
        }
427
0
        else if( o3tl::starts_with(aTypeName, u"FooterShape" ) )
428
0
        {
429
0
            nType = SdrObjKind::Text;
430
0
        }
431
0
        else if( o3tl::starts_with(aTypeName, u"HeaderShape" ) )
432
0
        {
433
0
            nType = SdrObjKind::Text;
434
0
        }
435
0
        else if( o3tl::starts_with(aTypeName, u"SlideNumberShape" ) )
436
0
        {
437
0
            nType = SdrObjKind::Text;
438
0
        }
439
0
        else if( o3tl::starts_with(aTypeName, u"DateTimeShape" ) )
440
0
        {
441
0
            nType = SdrObjKind::Text;
442
0
        }
443
0
        else if( o3tl::starts_with(aTypeName, u"TableShape" ) )
444
0
        {
445
0
            nType = SdrObjKind::Table;
446
0
        }
447
0
        else
448
0
        {
449
0
            throw lang::ServiceNotRegisteredException();
450
0
        }
451
452
        // create the API wrapper
453
0
        rtl::Reference<SvxShape> xNewShape = CreateSvxShapeByTypeAndInventor( nType, SdrInventor::Default, u""_ustr );
454
0
        pShape = xNewShape.get();
455
456
        // set shape type
457
0
        if( pShape )
458
0
            pShape->SetShapeType(aServiceSpecifier);
459
460
0
        xRet = cppu::getXWeak(pShape);
461
0
    }
462
0
    else
463
0
    {
464
0
        xRet = SvxFmMSFactory::createInstance( aServiceSpecifier );
465
0
    }
466
467
0
    return xRet;
468
0
}
469
470
uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getAvailableServiceNames()
471
0
{
472
0
    const uno::Sequence< OUString > aSNS_ORG( SvxFmMSFactory::getAvailableServiceNames() );
473
474
0
    static constexpr OUString aSNS[] {
475
0
        u"com.sun.star.drawing.DashTable"_ustr,
476
0
        u"com.sun.star.drawing.GradientTable"_ustr,
477
0
        u"com.sun.star.drawing.HatchTable"_ustr,
478
0
        u"com.sun.star.drawing.BitmapTable"_ustr,
479
0
        u"com.sun.star.drawing.TransparencyGradientTable"_ustr,
480
0
        u"com.sun.star.drawing.MarkerTable"_ustr,
481
0
        u"com.sun.star.text.NumberingRules"_ustr,
482
0
        u"com.sun.star.image.ImageMapRectangleObject"_ustr,
483
0
        u"com.sun.star.image.ImageMapCircleObject"_ustr,
484
0
        u"com.sun.star.image.ImageMapPolygonObject"_ustr,
485
486
0
        u"com.sun.star.presentation.TitleTextShape"_ustr,
487
0
        u"com.sun.star.presentation.OutlinerShape"_ustr,
488
0
        u"com.sun.star.presentation.SubtitleShape"_ustr,
489
0
        u"com.sun.star.presentation.GraphicObjectShape"_ustr,
490
0
        u"com.sun.star.presentation.ChartShape"_ustr,
491
0
        u"com.sun.star.presentation.PageShape"_ustr,
492
0
        u"com.sun.star.presentation.OLE2Shape"_ustr,
493
0
        u"com.sun.star.presentation.TableShape"_ustr,
494
0
        u"com.sun.star.presentation.OrgChartShape"_ustr,
495
0
        u"com.sun.star.presentation.NotesShape"_ustr,
496
0
        u"com.sun.star.presentation.HandoutShape"_ustr
497
0
    };
498
499
0
    return comphelper::concatSequences( aSNS_ORG, aSNS );
500
0
}
501
502
// lang::XServiceInfo
503
OUString SAL_CALL SvxUnoDrawingModel::getImplementationName()
504
0
{
505
0
    return u"SvxUnoDrawingModel"_ustr;
506
0
}
507
508
sal_Bool SAL_CALL SvxUnoDrawingModel::supportsService( const OUString& ServiceName )
509
0
{
510
0
    return cppu::supportsService( this, ServiceName );
511
0
}
512
513
uno::Sequence< OUString > SAL_CALL SvxUnoDrawingModel::getSupportedServiceNames()
514
0
{
515
0
    return { u"com.sun.star.drawing.DrawingDocument"_ustr };
516
0
}
517
518
// XAnyCompareFactory
519
uno::Reference< css::ucb::XAnyCompare > SAL_CALL SvxUnoDrawingModel::createAnyCompareByName( const OUString& )
520
0
{
521
0
    return SvxCreateNumRuleCompare();
522
0
}
523
524
SvxUnoDrawPagesAccess::SvxUnoDrawPagesAccess( SvxUnoDrawingModel& rMyModel )  noexcept
525
0
:   mrModel(rMyModel)
526
0
{
527
0
}
528
529
// XIndexAccess
530
sal_Int32 SAL_CALL SvxUnoDrawPagesAccess::getCount()
531
0
{
532
0
    ::SolarMutexGuard aGuard;
533
534
0
    sal_Int32 nCount = 0;
535
536
0
    if( mrModel.mpDoc )
537
0
        nCount = mrModel.mpDoc->GetPageCount();
538
539
0
    return nCount;
540
0
}
541
542
uno::Any SAL_CALL SvxUnoDrawPagesAccess::getByIndex( sal_Int32 Index )
543
0
{
544
0
    ::SolarMutexGuard aGuard;
545
546
0
    uno::Any aAny;
547
548
0
    if( mrModel.mpDoc )
549
0
    {
550
0
        if( (Index < 0) || (Index >= mrModel.mpDoc->GetPageCount() ) )
551
0
            throw lang::IndexOutOfBoundsException();
552
553
0
        SdrPage* pPage = mrModel.mpDoc->GetPage( static_cast<sal_uInt16>(Index) );
554
0
        if( pPage )
555
0
        {
556
0
            uno::Reference< uno::XInterface > xPage( pPage->mxUnoPage );
557
558
0
            if( !xPage.is() )
559
0
            {
560
0
                xPage = static_cast<drawing::XDrawPage*>(new SvxDrawPage( pPage ));
561
0
                pPage->mxUnoPage = xPage;
562
0
            }
563
564
0
            aAny <<= xPage;
565
0
        }
566
0
    }
567
0
    return aAny;
568
0
}
569
570
// XElementAccess
571
uno::Type SAL_CALL SvxUnoDrawPagesAccess::getElementType()
572
0
{
573
0
    return cppu::UnoType<drawing::XDrawPage>::get();
574
0
}
575
576
sal_Bool SAL_CALL SvxUnoDrawPagesAccess::hasElements()
577
0
{
578
0
    return getCount() > 0;
579
0
}
580
581
// XDrawPages
582
583
// create a new page with model at given position
584
// and return corresponding SdDrawPage
585
uno::Reference< drawing::XDrawPage > SAL_CALL SvxUnoDrawPagesAccess::insertNewByIndex( sal_Int32 nIndex )
586
0
{
587
0
    ::SolarMutexGuard aGuard;
588
589
0
    uno::Reference< drawing::XDrawPage > xDrawPage;
590
591
0
    if( mrModel.mpDoc )
592
0
    {
593
0
        rtl::Reference<SdrPage> pPage;
594
595
0
        if( auto pFormModel = dynamic_cast<FmFormModel*>( mrModel.mpDoc )  )
596
0
            pPage = new FmFormPage(*pFormModel);
597
0
        else
598
0
            pPage = new SdrPage(*mrModel.mpDoc);
599
600
0
        mrModel.mpDoc->InsertPage( pPage.get(), static_cast<sal_uInt16>(nIndex) );
601
0
        xDrawPage.set( pPage->getUnoPage(), uno::UNO_QUERY );
602
0
    }
603
604
0
    return xDrawPage;
605
0
}
606
607
void SAL_CALL SvxUnoDrawPagesAccess::remove( const uno::Reference< drawing::XDrawPage >& xPage )
608
0
{
609
0
    ::SolarMutexGuard aGuard;
610
611
0
    sal_uInt16 nPageCount = mrModel.mpDoc->GetPageCount();
612
0
    if( nPageCount <= 1 )
613
0
        return;
614
615
    // get pPage from xPage and get Id (nPos)
616
0
    SvxDrawPage* pSvxPage = comphelper::getFromUnoTunnel<SvxDrawPage>( xPage );
617
0
    if( pSvxPage )
618
0
    {
619
0
        SdrPage* pPage = pSvxPage->GetSdrPage();
620
0
        if(pPage)
621
0
        {
622
0
            sal_uInt16 nPage = pPage->GetPageNum();
623
0
            mrModel.mpDoc->DeletePage( nPage );
624
0
        }
625
0
    }
626
0
}
627
628
// XServiceInfo
629
630
OUString SAL_CALL SvxUnoDrawPagesAccess::getImplementationName(  )
631
0
{
632
0
    return u"SvxUnoDrawPagesAccess"_ustr;
633
0
}
634
635
sal_Bool SAL_CALL SvxUnoDrawPagesAccess::supportsService( const OUString& ServiceName )
636
0
{
637
0
    return cppu::supportsService(this, ServiceName);
638
0
}
639
640
uno::Sequence< OUString > SAL_CALL SvxUnoDrawPagesAccess::getSupportedServiceNames(  )
641
0
{
642
0
    return { u"com.sun.star.drawing.DrawPages"_ustr };
643
0
}
644
645
css::uno::Reference< css::container::XIndexReplace > SvxCreateNumRule(SdrModel* pModel)
646
1.35k
{
647
1.35k
    const SvxNumRule* pDefaultRule = nullptr;
648
1.35k
    if( pModel )
649
1.35k
    {
650
1.35k
        const SvxNumBulletItem* pItem = pModel->GetItemPool().GetSecondaryPool()->GetUserDefaultItem(EE_PARA_NUMBULLET);
651
1.35k
        if( pItem )
652
913
        {
653
913
            pDefaultRule = &pItem->GetNumRule();
654
913
        }
655
1.35k
    }
656
657
1.35k
    if( pDefaultRule )
658
913
    {
659
913
        return SvxCreateNumRule( *pDefaultRule );
660
913
    }
661
445
    else
662
445
    {
663
445
        SvxNumRule aTempRule( SvxNumRuleFlags::NONE, 10, false );
664
445
        return SvxCreateNumRule( aTempRule );
665
445
    }
666
1.35k
}
667
668
669
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */