Coverage Report

Created: 2026-09-28 10:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/unoobj/afmtuno.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 <scitems.hxx>
21
#include <editeng/memberids.h>
22
#include <osl/diagnose.h>
23
#include <svl/poolitem.hxx>
24
#include <vcl/svapp.hxx>
25
#include <svx/algitem.hxx>
26
#include <editeng/boxitem.hxx>
27
#include <svx/unomid.hxx>
28
#include <unowids.hxx>
29
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30
#include <com/sun/star/table/TableBorder.hpp>
31
#include <com/sun/star/table/CellHoriJustify.hpp>
32
#include <com/sun/star/table/CellOrientation.hpp>
33
#include <com/sun/star/table/TableBorder2.hpp>
34
#include <com/sun/star/awt/FontSlant.hpp>
35
36
#include <attrib.hxx>
37
#include <afmtuno.hxx>
38
#include <miscuno.hxx>
39
#include <autoform.hxx>
40
#include <scdll.hxx>
41
#include <unonames.hxx>
42
#include <cellsuno.hxx>
43
44
using namespace ::com::sun::star;
45
46
//  an AutoFormat has always 16 entries
47
0
#define SC_AF_FIELD_COUNT 16
48
49
//  AutoFormat map only for PropertySetInfo without Which-IDs
50
51
static std::span<const SfxItemPropertyMapEntry> lcl_GetAutoFormatMap()
52
0
{
53
0
    static const SfxItemPropertyMapEntry aAutoFormatMap_Impl[] =
54
0
    {
55
0
        { SC_UNONAME_INCBACK,  0,  cppu::UnoType<bool>::get(),    0, 0 },
56
0
        { SC_UNONAME_INCBORD,  0,  cppu::UnoType<bool>::get(),    0, 0 },
57
0
        { SC_UNONAME_INCFONT,  0,  cppu::UnoType<bool>::get(),    0, 0 },
58
0
        { SC_UNONAME_INCJUST,  0,  cppu::UnoType<bool>::get(),    0, 0 },
59
0
        { SC_UNONAME_INCNUM,   0,  cppu::UnoType<bool>::get(),    0, 0 },
60
0
        { SC_UNONAME_INCWIDTH, 0,  cppu::UnoType<bool>::get(),    0, 0 },
61
0
    };
62
0
    return aAutoFormatMap_Impl;
63
0
}
64
65
//! number format (String/Language) ??? (in XNumberFormat only ReadOnly)
66
//! table::TableBorder ??!?
67
68
static std::span<const SfxItemPropertyMapEntry> lcl_GetAutoFieldMap()
69
0
{
70
0
    static const SfxItemPropertyMapEntry aAutoFieldMap_Impl[] =
71
0
    {
72
0
        { SC_UNONAME_CELLBACK, ATTR_BACKGROUND,        ::cppu::UnoType<sal_Int32>::get(),        0, MID_BACK_COLOR },
73
0
        { SC_UNONAME_CCOLOR,   ATTR_FONT_COLOR,        ::cppu::UnoType<sal_Int32>::get(),        0, 0 },
74
0
        { SC_UNONAME_COUTL,    ATTR_FONT_CONTOUR,      cppu::UnoType<bool>::get(),                    0, 0 },
75
0
        { SC_UNONAME_CCROSS,   ATTR_FONT_CROSSEDOUT,   cppu::UnoType<bool>::get(),                    0, MID_CROSSED_OUT },
76
0
        { SC_UNONAME_CFONT,    ATTR_FONT,              ::cppu::UnoType<sal_Int16>::get(),        0, MID_FONT_FAMILY },
77
0
        { SC_UNONAME_CFCHARS,  ATTR_FONT,              ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_CHAR_SET },
78
0
        { SC_UNO_CJK_CFCHARS,  ATTR_CJK_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_CHAR_SET },
79
0
        { SC_UNO_CTL_CFCHARS,  ATTR_CTL_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_CHAR_SET },
80
0
        { SC_UNONAME_CFFAMIL,  ATTR_FONT,              ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_FAMILY },
81
0
        { SC_UNO_CJK_CFFAMIL,  ATTR_CJK_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_FAMILY },
82
0
        { SC_UNO_CTL_CFFAMIL,  ATTR_CTL_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_FAMILY },
83
0
        { SC_UNONAME_CFNAME,   ATTR_FONT,              ::cppu::UnoType<OUString>::get(),          0, MID_FONT_FAMILY_NAME },
84
0
        { SC_UNO_CJK_CFNAME,   ATTR_CJK_FONT,          ::cppu::UnoType<OUString>::get(),          0, MID_FONT_FAMILY_NAME },
85
0
        { SC_UNO_CTL_CFNAME,   ATTR_CTL_FONT,          ::cppu::UnoType<OUString>::get(),          0, MID_FONT_FAMILY_NAME },
86
0
        { SC_UNONAME_CFPITCH,  ATTR_FONT,              ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_PITCH },
87
0
        { SC_UNO_CJK_CFPITCH,  ATTR_CJK_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_PITCH },
88
0
        { SC_UNO_CTL_CFPITCH,  ATTR_CTL_FONT,          ::cppu::UnoType<sal_Int16>::get(),              0, MID_FONT_PITCH },
89
0
        { SC_UNONAME_CFSTYLE,  ATTR_FONT,              ::cppu::UnoType<OUString>::get(),          0, MID_FONT_STYLE_NAME },
90
0
        { SC_UNO_CJK_CFSTYLE,  ATTR_CJK_FONT,          ::cppu::UnoType<OUString>::get(),          0, MID_FONT_STYLE_NAME },
91
0
        { SC_UNO_CTL_CFSTYLE,  ATTR_CTL_FONT,          ::cppu::UnoType<OUString>::get(),          0, MID_FONT_STYLE_NAME },
92
0
        { SC_UNONAME_CHEIGHT,  ATTR_FONT_HEIGHT,       ::cppu::UnoType<float>::get(),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
93
0
        { SC_UNO_CJK_CHEIGHT,  ATTR_CJK_FONT_HEIGHT,   ::cppu::UnoType<float>::get(),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
94
0
        { SC_UNO_CTL_CHEIGHT,  ATTR_CTL_FONT_HEIGHT,   ::cppu::UnoType<float>::get(),                  0, MID_FONTHEIGHT | CONVERT_TWIPS },
95
0
        { SC_UNONAME_COVER,    ATTR_FONT_OVERLINE,     ::cppu::UnoType<sal_Int16>::get(),        0, MID_TL_STYLE },
96
0
        { SC_UNONAME_CPOST,    ATTR_FONT_POSTURE,      ::cppu::UnoType<awt::FontSlant>::get(),         0, MID_POSTURE },
97
0
        { SC_UNO_CJK_CPOST,    ATTR_CJK_FONT_POSTURE,  ::cppu::UnoType<awt::FontSlant>::get(),         0, MID_POSTURE },
98
0
        { SC_UNO_CTL_CPOST,    ATTR_CTL_FONT_POSTURE,  ::cppu::UnoType<awt::FontSlant>::get(),         0, MID_POSTURE },
99
0
        { SC_UNONAME_CSHADD,   ATTR_FONT_SHADOWED,     cppu::UnoType<bool>::get(),                    0, 0 },
100
0
        { SC_UNONAME_TBLBORD,  SC_WID_UNO_TBLBORD,     ::cppu::UnoType<table::TableBorder>::get(),     0, 0 | CONVERT_TWIPS },
101
0
        { SC_UNONAME_TBLBORD2,  SC_WID_UNO_TBLBORD2,     ::cppu::UnoType<table::TableBorder2>::get(),     0, 0 | CONVERT_TWIPS },
102
0
        { SC_UNONAME_CUNDER,   ATTR_FONT_UNDERLINE,    ::cppu::UnoType<sal_Int16>::get(),        0, MID_TL_STYLE },
103
0
        { SC_UNONAME_CWEIGHT,  ATTR_FONT_WEIGHT,       ::cppu::UnoType<float>::get(),                  0, MID_WEIGHT },
104
0
        { SC_UNO_CJK_CWEIGHT,  ATTR_CJK_FONT_WEIGHT,   ::cppu::UnoType<float>::get(),                  0, MID_WEIGHT },
105
0
        { SC_UNO_CTL_CWEIGHT,  ATTR_CTL_FONT_WEIGHT,   ::cppu::UnoType<float>::get(),                  0, MID_WEIGHT },
106
0
        { SC_UNONAME_CELLHJUS, ATTR_HOR_JUSTIFY,       ::cppu::UnoType<table::CellHoriJustify>::get(),   0, 0 },
107
0
        { SC_UNONAME_CELLHJUS_METHOD, ATTR_HOR_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(),   0, 0 },
108
0
        { SC_UNONAME_CELLTRAN, ATTR_BACKGROUND,        cppu::UnoType<bool>::get(),                    0, MID_GRAPHIC_TRANSPARENT },
109
0
        { SC_UNONAME_WRAP,     ATTR_LINEBREAK,         cppu::UnoType<bool>::get(),                    0, 0 },
110
0
        { SC_UNONAME_CELLORI,  ATTR_STACKED,           ::cppu::UnoType<table::CellOrientation>::get(),   0, 0 },
111
0
        { SC_UNONAME_PBMARGIN, ATTR_MARGIN,            ::cppu::UnoType<sal_Int32>::get(),        0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
112
0
        { SC_UNONAME_PLMARGIN, ATTR_MARGIN,            ::cppu::UnoType<sal_Int32>::get(),        0, MID_MARGIN_L_MARGIN  | CONVERT_TWIPS },
113
0
        { SC_UNONAME_PRMARGIN, ATTR_MARGIN,            ::cppu::UnoType<sal_Int32>::get(),        0, MID_MARGIN_R_MARGIN  | CONVERT_TWIPS },
114
0
        { SC_UNONAME_PTMARGIN, ATTR_MARGIN,            ::cppu::UnoType<sal_Int32>::get(),        0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
115
0
        { SC_UNONAME_ROTANG,   ATTR_ROTATE_VALUE,      ::cppu::UnoType<sal_Int32>::get(),        0, 0 },
116
0
        { SC_UNONAME_ROTREF,   ATTR_ROTATE_MODE,       ::cppu::UnoType<sal_Int32>::get(),   0, 0 },
117
0
        { SC_UNONAME_CELLVJUS, ATTR_VER_JUSTIFY,       ::cppu::UnoType<sal_Int32>::get(),   0, 0 },
118
0
        { SC_UNONAME_CELLVJUS_METHOD, ATTR_VER_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(),   0, 0 },
119
0
    };
120
0
    return aAutoFieldMap_Impl;
121
0
}
122
123
constexpr OUString SCAUTOFORMATSOBJ_SERVICE = u"com.sun.star.sheet.TableAutoFormats"_ustr;
124
125
SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, u"ScAutoFormatFieldObj"_ustr, u"com.sun.star.sheet.TableAutoFormatField"_ustr )
126
SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, u"ScAutoFormatObj"_ustr, u"com.sun.star.sheet.TableAutoFormat"_ustr )
127
SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, u"stardiv.StarCalc.ScAutoFormatsObj"_ustr, SCAUTOFORMATSOBJ_SERVICE )
128
129
static bool lcl_FindAutoFormatIndex(const ScAutoFormat& rFormats, std::u16string_view rName,
130
                                    sal_uInt16& rOutIndex)
131
0
{
132
0
    for (size_t i = 0; i < rFormats.size(); i++)
133
0
    {
134
0
        const ScAutoFormatData* pData = rFormats.GetData(i);
135
0
        if (pData->GetName() == rName)
136
0
        {
137
0
            rOutIndex = i;
138
0
            return true;
139
0
        }
140
0
    }
141
0
    return false;
142
0
}
143
144
ScAutoFormatsObj::ScAutoFormatsObj()
145
0
{
146
    //! This object should only exist once and it must be known to Auto-Format-Data,
147
    //! so that changes can be broadcasted
148
0
}
149
150
ScAutoFormatsObj::~ScAutoFormatsObj()
151
0
{
152
0
}
153
154
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
155
ScAutoFormatsObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
156
0
{
157
0
    SolarMutexGuard aGuard;
158
0
    ScDLL::Init();
159
0
    return cppu::acquire(new ScAutoFormatsObj);
160
0
}
161
162
// XTableAutoFormats
163
164
rtl::Reference<ScAutoFormatObj> ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
165
0
{
166
0
    if (nIndex < ScGlobal::GetOrCreateAutoFormat()->size())
167
0
        return new ScAutoFormatObj(nIndex);
168
169
0
    return nullptr;    // wrong index
170
0
}
171
172
rtl::Reference<ScAutoFormatObj> ScAutoFormatsObj::GetObjectByName_Impl(std::u16string_view aName)
173
0
{
174
0
    sal_uInt16 nIndex;
175
0
    if (lcl_FindAutoFormatIndex(
176
0
            *ScGlobal::GetOrCreateAutoFormat(), aName, nIndex ))
177
0
        return GetObjectByIndex_Impl(nIndex);
178
0
    return nullptr;
179
0
}
180
181
// container::XNameContainer
182
183
void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::Any& aElement )
184
0
{
185
0
    SolarMutexGuard aGuard;
186
0
    bool bDone = false;
187
    //  Reflection need not be uno::XInterface, can be any interface...
188
0
    uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY);
189
0
    if ( xInterface.is() )
190
0
    {
191
0
        ScAutoFormatObj* pFormatObj = dynamic_cast<ScAutoFormatObj*>( xInterface.get() );
192
0
        if ( pFormatObj && !pFormatObj->IsInserted() )
193
0
        {
194
0
            ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
195
196
0
            sal_uInt16 nDummy;
197
0
            if (lcl_FindAutoFormatIndex( *pFormats, aName, nDummy ))
198
0
            {
199
0
                throw container::ElementExistException();
200
0
            }
201
202
0
            ScAutoFormatData* pNew = new ScAutoFormatData();
203
0
            pNew->SetName( aName );
204
205
0
            if (pFormats->InsertAutoFormat(pNew))
206
0
            {
207
                //! notify to other objects
208
0
                pFormats->Save();
209
210
0
                sal_uInt16 nNewIndex;
211
0
                if (lcl_FindAutoFormatIndex( *pFormats, aName, nNewIndex ))
212
0
                {
213
0
                    pFormatObj->InitFormat( nNewIndex );    // can be used now
214
0
                    bDone = true;
215
0
                }
216
217
0
                ScGlobal::ResetAutoFormat();
218
0
            }
219
0
            else
220
0
            {
221
0
                OSL_FAIL("AutoFormat could not be inserted");
222
0
                throw uno::RuntimeException();
223
0
            }
224
0
        }
225
0
    }
226
227
0
    if (!bDone)
228
0
    {
229
        //  other errors are handled above
230
0
        throw lang::IllegalArgumentException();
231
0
    }
232
0
}
233
234
void SAL_CALL ScAutoFormatsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
235
0
{
236
0
    SolarMutexGuard aGuard;
237
    //! combine?
238
0
    removeByName( aName );
239
0
    insertByName( aName, aElement );
240
0
}
241
242
void SAL_CALL ScAutoFormatsObj::removeByName( const OUString& aName )
243
0
{
244
0
    SolarMutexGuard aGuard;
245
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
246
0
    ScAutoFormatData* pData = pFormats->FindAutoFormat(aName);
247
0
    if (!pData)
248
0
    {
249
0
        throw container::NoSuchElementException();
250
0
    }
251
0
    pFormats->ReleaseAutoFormat(aName);
252
253
    //! notify to other objects
254
0
    pFormats->Save();   // save immediately
255
0
    ScGlobal::ResetAutoFormat();
256
0
}
257
258
// container::XEnumerationAccess
259
260
uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
261
0
{
262
0
    SolarMutexGuard aGuard;
263
0
    return new ScIndexEnumeration(this, u"com.sun.star.sheet.TableAutoFormatEnumeration"_ustr);
264
0
}
265
266
// container::XIndexAccess
267
268
sal_Int32 SAL_CALL ScAutoFormatsObj::getCount()
269
0
{
270
0
    SolarMutexGuard aGuard;
271
0
    return ScGlobal::GetOrCreateAutoFormat()->size();
272
0
}
273
274
uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
275
0
{
276
0
    SolarMutexGuard aGuard;
277
0
    rtl::Reference< ScAutoFormatObj > xFormat(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex)));
278
0
    if (!xFormat.is())
279
0
        throw lang::IndexOutOfBoundsException();
280
0
    return uno::Any(uno::Reference< container::XNamed >(xFormat));
281
0
}
282
283
uno::Type SAL_CALL ScAutoFormatsObj::getElementType()
284
0
{
285
0
    return cppu::UnoType<container::XNamed>::get();    // must match getByIndex
286
0
}
287
288
sal_Bool SAL_CALL ScAutoFormatsObj::hasElements()
289
0
{
290
0
    SolarMutexGuard aGuard;
291
0
    return ( getCount() != 0 );
292
0
}
293
294
// container::XNameAccess
295
296
uno::Any SAL_CALL ScAutoFormatsObj::getByName( const OUString& aName )
297
0
{
298
0
    SolarMutexGuard aGuard;
299
0
    rtl::Reference< ScAutoFormatObj > xFormat(GetObjectByName_Impl(aName));
300
0
    if (!xFormat.is())
301
0
        throw container::NoSuchElementException();
302
0
    return uno::Any(uno::Reference< container::XNamed >(xFormat));
303
0
}
304
305
uno::Sequence<OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
306
0
{
307
0
    SolarMutexGuard aGuard;
308
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
309
0
    uno::Sequence<OUString> aSeq(pFormats->size());
310
0
    OUString* pAry = aSeq.getArray();
311
0
    for (size_t i = 0; i < pFormats->size(); i++)
312
0
    {
313
0
        ScAutoFormatData* pData = pFormats->GetData(i);
314
0
        if (pData)
315
0
            pAry[i] = pData->GetName();
316
0
    }
317
0
    return aSeq;
318
0
}
319
320
sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const OUString& aName )
321
0
{
322
0
    SolarMutexGuard aGuard;
323
0
    auto pData = ScGlobal::GetOrCreateAutoFormat()->FindAutoFormat(aName);
324
0
    return pData ? true : false;
325
0
}
326
327
ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
328
0
    aPropSet( lcl_GetAutoFormatMap() ),
329
0
    nFormatIndex( nIndex )
330
0
{
331
0
}
332
333
ScAutoFormatObj::~ScAutoFormatObj()
334
0
{
335
0
}
336
337
void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex )
338
0
{
339
0
    OSL_ENSURE( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat is multiple" );
340
0
    nFormatIndex = nNewIndex;
341
0
}
342
343
// XTableAutoFormat
344
345
rtl::Reference<ScAutoFormatFieldObj> ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
346
0
{
347
0
    if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
348
0
        return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
349
350
0
    return nullptr;
351
0
}
352
353
// container::XEnumerationAccess
354
355
uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
356
0
{
357
0
    SolarMutexGuard aGuard;
358
0
    return new ScIndexEnumeration(this, u"com.sun.star.sheet.TableAutoFormatEnumeration"_ustr);
359
0
}
360
361
// container::XIndexAccess
362
363
sal_Int32 SAL_CALL ScAutoFormatObj::getCount()
364
0
{
365
0
    SolarMutexGuard aGuard;
366
0
    if (IsInserted())
367
0
        return SC_AF_FIELD_COUNT;   // always 16 elements
368
0
    else
369
0
        return 0;
370
0
}
371
372
uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
373
0
{
374
0
    SolarMutexGuard aGuard;
375
376
0
    if ( nIndex < 0 || nIndex >= getCount() )
377
0
        throw lang::IndexOutOfBoundsException();
378
379
0
    if (IsInserted())
380
0
        return uno::Any(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex))));
381
0
    return uno::Any();
382
0
}
383
384
uno::Type SAL_CALL ScAutoFormatObj::getElementType()
385
0
{
386
0
    return cppu::UnoType<beans::XPropertySet>::get();  // must match getByIndex
387
0
}
388
389
sal_Bool SAL_CALL ScAutoFormatObj::hasElements()
390
0
{
391
0
    SolarMutexGuard aGuard;
392
0
    return ( getCount() != 0 );
393
0
}
394
395
// container::XNamed
396
397
OUString SAL_CALL ScAutoFormatObj::getName()
398
0
{
399
0
    SolarMutexGuard aGuard;
400
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
401
0
    if (IsInserted() && nFormatIndex < pFormats->size())
402
0
        return pFormats->GetData(nFormatIndex)->GetName();
403
404
0
    return OUString();
405
0
}
406
407
void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
408
0
{
409
0
    SolarMutexGuard aGuard;
410
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
411
412
0
    sal_uInt16 nDummy;
413
0
    if (!IsInserted() || nFormatIndex >= pFormats->size() ||
414
0
        lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
415
0
    {
416
        //  not inserted or name exists
417
0
        throw uno::RuntimeException();
418
0
    }
419
420
0
    if (ScAutoFormatData* pData = pFormats->GetData(nFormatIndex))
421
0
    {
422
0
        pData->SetName(aNewName);
423
0
    }
424
0
    else
425
0
    {
426
0
        OSL_FAIL("AutoFormat could not be inserted");
427
0
        nFormatIndex = 0;       //! old index invalid
428
0
    }
429
0
}
430
431
// beans::XPropertySet
432
433
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo()
434
0
{
435
0
    SolarMutexGuard aGuard;
436
0
    static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
437
0
    return aRef;
438
0
}
439
440
void SAL_CALL ScAutoFormatObj::setPropertyValue(
441
                        const OUString& aPropertyName, const uno::Any& aValue )
442
0
{
443
0
    SolarMutexGuard aGuard;
444
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
445
0
    if (!(IsInserted() && nFormatIndex < pFormats->size()))
446
0
        return;
447
448
0
    ScAutoFormatData* pData = pFormats->GetData(nFormatIndex);
449
0
    OSL_ENSURE(pData,"AutoFormat data not available");
450
451
0
    bool bBool = false;
452
0
    if (aPropertyName == SC_UNONAME_INCBACK && (aValue >>= bBool))
453
0
        pData->SetBackground( bBool );
454
0
    else if (aPropertyName == SC_UNONAME_INCBORD && (aValue >>= bBool))
455
0
        pData->SetFrame( bBool );
456
0
    else if (aPropertyName == SC_UNONAME_INCFONT && (aValue >>= bBool))
457
0
        pData->SetFont( bBool );
458
0
    else if (aPropertyName == SC_UNONAME_INCJUST && (aValue >>= bBool))
459
0
        pData->SetJustify( bBool );
460
0
    else if (aPropertyName == SC_UNONAME_INCNUM && (aValue >>= bBool))
461
0
        pData->SetValueFormat( bBool );
462
0
    else if (aPropertyName == SC_UNONAME_INCWIDTH && (aValue >>= bBool))
463
0
        pData->SetWidthHeight( bBool );
464
465
    // else error
466
467
    //! notify to other objects
468
0
    pFormats->Save();
469
0
}
470
471
uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const OUString& aPropertyName )
472
0
{
473
0
    SolarMutexGuard aGuard;
474
0
    uno::Any aAny;
475
476
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
477
0
    if (IsInserted() && nFormatIndex < pFormats->size())
478
0
    {
479
0
        ScAutoFormatData* pData = pFormats->GetData(nFormatIndex);
480
0
        assert(pData && "AutoFormat data not available");
481
482
0
        bool bValue;
483
0
        bool bError = false;
484
485
0
        if (aPropertyName == SC_UNONAME_INCBACK)
486
0
            bValue = pData->IsBackground();
487
0
        else if (aPropertyName == SC_UNONAME_INCBORD)
488
0
            bValue = pData->IsFrame();
489
0
        else if (aPropertyName == SC_UNONAME_INCFONT)
490
0
            bValue = pData->IsFont();
491
0
        else if (aPropertyName == SC_UNONAME_INCJUST)
492
0
            bValue = pData->IsJustify();
493
0
        else if (aPropertyName == SC_UNONAME_INCNUM)
494
0
            bValue = pData->IsValueFormat();
495
0
        else if (aPropertyName == SC_UNONAME_INCWIDTH)
496
0
            bValue = pData->IsWidthHeight();
497
0
        else
498
0
            bError = true;      // unknown property
499
500
0
        if (!bError)
501
0
            aAny <<= bValue;
502
0
    }
503
504
0
    return aAny;
505
0
}
506
507
SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj )
508
509
ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) :
510
0
    aPropSet( lcl_GetAutoFieldMap() ),
511
0
    nFormatIndex( nFormat ),
512
0
    nFieldIndex( nField )
513
0
{
514
0
}
515
516
ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
517
0
{
518
0
}
519
520
// beans::XPropertySet
521
522
uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
523
0
{
524
0
    SolarMutexGuard aGuard;
525
0
    static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
526
0
    return aRef;
527
0
}
528
529
void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
530
                        const OUString& aPropertyName, const uno::Any& aValue )
531
0
{
532
0
    SolarMutexGuard aGuard;
533
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
534
0
    const SfxItemPropertyMapEntry* pEntry =
535
0
            aPropSet.getPropertyMap().getByName( aPropertyName );
536
537
0
    if ( !(pEntry && pEntry->nWID && nFormatIndex < pFormats->size()) )
538
0
        return;
539
540
0
    ScAutoFormatData* pData = pFormats->GetData(nFormatIndex);
541
542
0
    if ( IsScItemWid( pEntry->nWID ) )
543
0
    {
544
0
        if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
545
0
        {
546
0
            bool bDone = false;
547
548
0
            switch( pEntry->nWID )
549
0
            {
550
0
                case ATTR_STACKED:
551
0
                {
552
0
                    table::CellOrientation eOrient;
553
0
                    if( aValue >>= eOrient )
554
0
                    {
555
0
                        switch( eOrient )
556
0
                        {
557
0
                            case table::CellOrientation_STANDARD:
558
0
                                pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
559
0
                            break;
560
0
                            case table::CellOrientation_TOPBOTTOM:
561
0
                                pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
562
0
                                pData->PutItem( nFieldIndex, ScRotateValueItem( 27000_deg100 ) );
563
0
                            break;
564
0
                            case table::CellOrientation_BOTTOMTOP:
565
0
                                pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
566
0
                                pData->PutItem( nFieldIndex, ScRotateValueItem( 9000_deg100 ) );
567
0
                            break;
568
0
                            case table::CellOrientation_STACKED:
569
0
                                pData->PutItem( nFieldIndex, ScVerticalStackCell( true ) );
570
0
                            break;
571
0
                            default:
572
0
                            {
573
                                // added to avoid warnings
574
0
                            }
575
0
                        }
576
0
                        bDone = true;
577
0
                    }
578
0
                }
579
0
                break;
580
0
                default:
581
0
                    std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
582
0
                    bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
583
0
                    if (bDone)
584
0
                        pData->PutItem( nFieldIndex, *pNewItem );
585
0
            }
586
587
0
            if (bDone)
588
                //! Notify to other objects?
589
0
                pFormats->Save();
590
0
        }
591
0
    }
592
0
    else
593
0
    {
594
0
        switch (pEntry->nWID)
595
0
        {
596
0
            case SC_WID_UNO_TBLBORD:
597
0
                {
598
0
                    table::TableBorder aBorder;
599
0
                    if ( aValue >>= aBorder )   // empty = nothing to do
600
0
                    {
601
0
                        SvxBoxItem aOuter(ATTR_BORDER);
602
0
                        SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
603
0
                        ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
604
0
                        pData->PutItem( nFieldIndex, aOuter );
605
606
                        //! Notify for other objects?
607
0
                        pFormats->Save();
608
0
                    }
609
0
                }
610
0
                break;
611
0
            case SC_WID_UNO_TBLBORD2:
612
0
                {
613
0
                    table::TableBorder2 aBorder2;
614
0
                    if ( aValue >>= aBorder2 )   // empty = nothing to do
615
0
                    {
616
0
                        SvxBoxItem aOuter(ATTR_BORDER);
617
0
                        SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
618
0
                        ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder2 );
619
0
                        pData->PutItem( nFieldIndex, aOuter );
620
621
                        //! Notify for other objects?
622
0
                        pFormats->Save();
623
0
                    }
624
0
                }
625
0
                break;
626
0
        }
627
0
    }
628
0
}
629
630
uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const OUString& aPropertyName )
631
0
{
632
0
    SolarMutexGuard aGuard;
633
0
    uno::Any aVal;
634
635
0
    ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
636
0
    const SfxItemPropertyMapEntry* pEntry =
637
0
            aPropSet.getPropertyMap().getByName( aPropertyName );
638
639
0
    if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
640
0
    {
641
0
        const ScAutoFormatData* pData = pFormats->GetData(nFormatIndex);
642
643
0
        if ( IsScItemWid( pEntry->nWID ) )
644
0
        {
645
0
            if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
646
0
            {
647
0
                switch( pEntry->nWID )
648
0
                {
649
0
                    case ATTR_STACKED:
650
0
                    {
651
0
                        const ScRotateValueItem* pRotItem = pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE );
652
0
                        Degree100 nRot = pRotItem ? pRotItem->GetValue() : 0_deg100;
653
0
                        bool bStacked = static_cast<const ScVerticalStackCell*>(pItem)->GetValue();
654
0
                        SvxOrientationItem( nRot, bStacked, TypedWhichId<SvxOrientationItem>(0) ).QueryValue( aVal );
655
0
                    }
656
0
                    break;
657
0
                    default:
658
0
                        pItem->QueryValue( aVal, pEntry->nMemberId );
659
0
                }
660
0
            }
661
0
        }
662
0
        else
663
0
        {
664
0
            switch (pEntry->nWID)
665
0
            {
666
0
                case SC_WID_UNO_TBLBORD:
667
0
                case SC_WID_UNO_TBLBORD2:
668
0
                    {
669
0
                        const SvxBoxItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
670
0
                        if (pItem)
671
0
                        {
672
0
                            SvxBoxItem aOuter(*pItem);
673
0
                            SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
674
675
0
                            if (pEntry->nWID == SC_WID_UNO_TBLBORD2)
676
0
                                ScHelperFunctions::AssignTableBorder2ToAny( aVal, aOuter, aInner);
677
0
                            else
678
0
                                ScHelperFunctions::AssignTableBorderToAny( aVal, aOuter, aInner);
679
0
                        }
680
0
                    }
681
0
                    break;
682
0
            }
683
0
        }
684
0
    }
685
686
0
    return aVal;
687
0
}
688
689
SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
690
691
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */