cid#1640468 Dereference after null check
[LibreOffice.git] / sc / source / ui / unoobj / afmtuno.cxx
blobbd1776fd07603429c9c42c2243d419b8fc302401
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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>
44 using namespace ::com::sun::star;
46 // an AutoFormat has always 16 entries
47 #define SC_AF_FIELD_COUNT 16
49 // AutoFormat map only for PropertySetInfo without Which-IDs
51 static std::span<const SfxItemPropertyMapEntry> lcl_GetAutoFormatMap()
53 static const SfxItemPropertyMapEntry aAutoFormatMap_Impl[] =
55 { SC_UNONAME_INCBACK, 0, cppu::UnoType<bool>::get(), 0, 0 },
56 { SC_UNONAME_INCBORD, 0, cppu::UnoType<bool>::get(), 0, 0 },
57 { SC_UNONAME_INCFONT, 0, cppu::UnoType<bool>::get(), 0, 0 },
58 { SC_UNONAME_INCJUST, 0, cppu::UnoType<bool>::get(), 0, 0 },
59 { SC_UNONAME_INCNUM, 0, cppu::UnoType<bool>::get(), 0, 0 },
60 { SC_UNONAME_INCWIDTH, 0, cppu::UnoType<bool>::get(), 0, 0 },
62 return aAutoFormatMap_Impl;
65 //! number format (String/Language) ??? (in XNumberFormat only ReadOnly)
66 //! table::TableBorder ??!?
68 static std::span<const SfxItemPropertyMapEntry> lcl_GetAutoFieldMap()
70 static const SfxItemPropertyMapEntry aAutoFieldMap_Impl[] =
72 { SC_UNONAME_CELLBACK, ATTR_BACKGROUND, ::cppu::UnoType<sal_Int32>::get(), 0, MID_BACK_COLOR },
73 { SC_UNONAME_CCOLOR, ATTR_FONT_COLOR, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
74 { SC_UNONAME_COUTL, ATTR_FONT_CONTOUR, cppu::UnoType<bool>::get(), 0, 0 },
75 { SC_UNONAME_CCROSS, ATTR_FONT_CROSSEDOUT, cppu::UnoType<bool>::get(), 0, MID_CROSSED_OUT },
76 { SC_UNONAME_CFONT, ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
77 { SC_UNONAME_CFCHARS, ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
78 { SC_UNO_CJK_CFCHARS, ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
79 { SC_UNO_CTL_CFCHARS, ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
80 { SC_UNONAME_CFFAMIL, ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
81 { SC_UNO_CJK_CFFAMIL, ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
82 { SC_UNO_CTL_CFFAMIL, ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
83 { SC_UNONAME_CFNAME, ATTR_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
84 { SC_UNO_CJK_CFNAME, ATTR_CJK_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
85 { SC_UNO_CTL_CFNAME, ATTR_CTL_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
86 { SC_UNONAME_CFPITCH, ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
87 { SC_UNO_CJK_CFPITCH, ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
88 { SC_UNO_CTL_CFPITCH, ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
89 { SC_UNONAME_CFSTYLE, ATTR_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
90 { SC_UNO_CJK_CFSTYLE, ATTR_CJK_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
91 { SC_UNO_CTL_CFSTYLE, ATTR_CTL_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
92 { SC_UNONAME_CHEIGHT, ATTR_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
93 { SC_UNO_CJK_CHEIGHT, ATTR_CJK_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
94 { SC_UNO_CTL_CHEIGHT, ATTR_CTL_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
95 { SC_UNONAME_COVER, ATTR_FONT_OVERLINE, ::cppu::UnoType<sal_Int16>::get(), 0, MID_TL_STYLE },
96 { SC_UNONAME_CPOST, ATTR_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
97 { SC_UNO_CJK_CPOST, ATTR_CJK_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
98 { SC_UNO_CTL_CPOST, ATTR_CTL_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
99 { SC_UNONAME_CSHADD, ATTR_FONT_SHADOWED, cppu::UnoType<bool>::get(), 0, 0 },
100 { SC_UNONAME_TBLBORD, SC_WID_UNO_TBLBORD, ::cppu::UnoType<table::TableBorder>::get(), 0, 0 | CONVERT_TWIPS },
101 { SC_UNONAME_TBLBORD2, SC_WID_UNO_TBLBORD2, ::cppu::UnoType<table::TableBorder2>::get(), 0, 0 | CONVERT_TWIPS },
102 { SC_UNONAME_CUNDER, ATTR_FONT_UNDERLINE, ::cppu::UnoType<sal_Int16>::get(), 0, MID_TL_STYLE },
103 { SC_UNONAME_CWEIGHT, ATTR_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
104 { SC_UNO_CJK_CWEIGHT, ATTR_CJK_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
105 { SC_UNO_CTL_CWEIGHT, ATTR_CTL_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
106 { SC_UNONAME_CELLHJUS, ATTR_HOR_JUSTIFY, ::cppu::UnoType<table::CellHoriJustify>::get(), 0, 0 },
107 { SC_UNONAME_CELLHJUS_METHOD, ATTR_HOR_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
108 { SC_UNONAME_CELLTRAN, ATTR_BACKGROUND, cppu::UnoType<bool>::get(), 0, MID_GRAPHIC_TRANSPARENT },
109 { SC_UNONAME_WRAP, ATTR_LINEBREAK, cppu::UnoType<bool>::get(), 0, 0 },
110 { SC_UNONAME_CELLORI, ATTR_STACKED, ::cppu::UnoType<table::CellOrientation>::get(), 0, 0 },
111 { SC_UNONAME_PBMARGIN, ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
112 { SC_UNONAME_PLMARGIN, ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS },
113 { SC_UNONAME_PRMARGIN, ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS },
114 { SC_UNONAME_PTMARGIN, ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
115 { SC_UNONAME_ROTANG, ATTR_ROTATE_VALUE, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
116 { SC_UNONAME_ROTREF, ATTR_ROTATE_MODE, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
117 { SC_UNONAME_CELLVJUS, ATTR_VER_JUSTIFY, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
118 { SC_UNONAME_CELLVJUS_METHOD, ATTR_VER_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
120 return aAutoFieldMap_Impl;
123 constexpr OUString SCAUTOFORMATSOBJ_SERVICE = u"com.sun.star.sheet.TableAutoFormats"_ustr;
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 )
129 static bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, std::u16string_view rName, sal_uInt16& rOutIndex )
131 ScAutoFormat::const_iterator itBeg = rFormats.begin(), itEnd = rFormats.end();
132 for (ScAutoFormat::const_iterator it = itBeg; it != itEnd; ++it)
134 const ScAutoFormatData *const pEntry = it->second.get();
135 const OUString& aEntryName = pEntry->GetName();
136 if ( aEntryName == rName )
138 size_t nPos = std::distance(itBeg, it);
139 rOutIndex = nPos;
140 return true;
143 return false;
146 ScAutoFormatsObj::ScAutoFormatsObj()
148 //! This object should only exist once and it must be known to Auto-Format-Data,
149 //! so that changes can be broadcasted
152 ScAutoFormatsObj::~ScAutoFormatsObj()
156 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
157 ScAutoFormatsObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
159 SolarMutexGuard aGuard;
160 ScDLL::Init();
161 return cppu::acquire(new ScAutoFormatsObj);
164 // XTableAutoFormats
166 rtl::Reference<ScAutoFormatObj> ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
168 if (nIndex < ScGlobal::GetOrCreateAutoFormat()->size())
169 return new ScAutoFormatObj(nIndex);
171 return nullptr; // wrong index
174 rtl::Reference<ScAutoFormatObj> ScAutoFormatsObj::GetObjectByName_Impl(std::u16string_view aName)
176 sal_uInt16 nIndex;
177 if (lcl_FindAutoFormatIndex(
178 *ScGlobal::GetOrCreateAutoFormat(), aName, nIndex ))
179 return GetObjectByIndex_Impl(nIndex);
180 return nullptr;
183 // container::XNameContainer
185 void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::Any& aElement )
187 SolarMutexGuard aGuard;
188 bool bDone = false;
189 // Reflection need not be uno::XInterface, can be any interface...
190 uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY);
191 if ( xInterface.is() )
193 ScAutoFormatObj* pFormatObj = dynamic_cast<ScAutoFormatObj*>( xInterface.get() );
194 if ( pFormatObj && !pFormatObj->IsInserted() )
196 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
198 sal_uInt16 nDummy;
199 if (lcl_FindAutoFormatIndex( *pFormats, aName, nDummy ))
201 throw container::ElementExistException();
204 std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData());
205 pNew->SetName( aName );
207 if (pFormats->insert(std::move(pNew)) != pFormats->end())
209 //! notify to other objects
210 pFormats->Save();
212 sal_uInt16 nNewIndex;
213 if (lcl_FindAutoFormatIndex( *pFormats, aName, nNewIndex ))
215 pFormatObj->InitFormat( nNewIndex ); // can be used now
216 bDone = true;
219 else
221 OSL_FAIL("AutoFormat could not be inserted");
222 throw uno::RuntimeException();
227 if (!bDone)
229 // other errors are handled above
230 throw lang::IllegalArgumentException();
234 void SAL_CALL ScAutoFormatsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
236 SolarMutexGuard aGuard;
237 //! combine?
238 removeByName( aName );
239 insertByName( aName, aElement );
242 void SAL_CALL ScAutoFormatsObj::removeByName( const OUString& aName )
244 SolarMutexGuard aGuard;
245 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
247 ScAutoFormat::iterator it = pFormats->find(aName);
248 if (it == pFormats->end())
250 throw container::NoSuchElementException();
252 pFormats->erase(it);
254 //! notify to other objects
255 pFormats->Save(); // save immediately
259 // container::XEnumerationAccess
261 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
263 SolarMutexGuard aGuard;
264 return new ScIndexEnumeration(this, u"com.sun.star.sheet.TableAutoFormatEnumeration"_ustr);
267 // container::XIndexAccess
269 sal_Int32 SAL_CALL ScAutoFormatsObj::getCount()
271 SolarMutexGuard aGuard;
272 return ScGlobal::GetOrCreateAutoFormat()->size();
275 uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
277 SolarMutexGuard aGuard;
278 uno::Reference< container::XNamed > xFormat(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex)));
279 if (!xFormat.is())
280 throw lang::IndexOutOfBoundsException();
281 return uno::Any(xFormat);
284 uno::Type SAL_CALL ScAutoFormatsObj::getElementType()
286 return cppu::UnoType<container::XNamed>::get(); // must match getByIndex
289 sal_Bool SAL_CALL ScAutoFormatsObj::hasElements()
291 SolarMutexGuard aGuard;
292 return ( getCount() != 0 );
295 // container::XNameAccess
297 uno::Any SAL_CALL ScAutoFormatsObj::getByName( const OUString& aName )
299 SolarMutexGuard aGuard;
300 uno::Reference< container::XNamed > xFormat(GetObjectByName_Impl(aName));
301 if (!xFormat.is())
302 throw container::NoSuchElementException();
303 return uno::Any(xFormat);
306 uno::Sequence<OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
308 SolarMutexGuard aGuard;
309 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
310 uno::Sequence<OUString> aSeq(pFormats->size());
311 OUString* pAry = aSeq.getArray();
312 size_t i = 0;
313 for (const auto& rEntry : *pFormats)
315 pAry[i] = rEntry.second->GetName();
316 ++i;
318 return aSeq;
321 sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const OUString& aName )
323 SolarMutexGuard aGuard;
324 sal_uInt16 nDummy;
325 return lcl_FindAutoFormatIndex(
326 *ScGlobal::GetOrCreateAutoFormat(), aName, nDummy );
329 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
330 aPropSet( lcl_GetAutoFormatMap() ),
331 nFormatIndex( nIndex )
335 ScAutoFormatObj::~ScAutoFormatObj()
337 // If an AutoFormat object is released, then eventually changes are saved
338 // so that they become visible in e.g Writer
340 if (IsInserted())
342 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
343 if ( pFormats && pFormats->IsSaveLater() )
344 pFormats->Save();
346 // Save() resets flag SaveLater
350 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex )
352 OSL_ENSURE( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat is multiple" );
353 nFormatIndex = nNewIndex;
356 // XTableAutoFormat
358 rtl::Reference<ScAutoFormatFieldObj> ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
360 if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
361 return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
363 return nullptr;
366 // container::XEnumerationAccess
368 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
370 SolarMutexGuard aGuard;
371 return new ScIndexEnumeration(this, u"com.sun.star.sheet.TableAutoFormatEnumeration"_ustr);
374 // container::XIndexAccess
376 sal_Int32 SAL_CALL ScAutoFormatObj::getCount()
378 SolarMutexGuard aGuard;
379 if (IsInserted())
380 return SC_AF_FIELD_COUNT; // always 16 elements
381 else
382 return 0;
385 uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
387 SolarMutexGuard aGuard;
389 if ( nIndex < 0 || nIndex >= getCount() )
390 throw lang::IndexOutOfBoundsException();
392 if (IsInserted())
393 return uno::Any(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl(static_cast<sal_uInt16>(nIndex))));
394 return uno::Any();
397 uno::Type SAL_CALL ScAutoFormatObj::getElementType()
399 return cppu::UnoType<beans::XPropertySet>::get(); // must match getByIndex
402 sal_Bool SAL_CALL ScAutoFormatObj::hasElements()
404 SolarMutexGuard aGuard;
405 return ( getCount() != 0 );
408 // container::XNamed
410 OUString SAL_CALL ScAutoFormatObj::getName()
412 SolarMutexGuard aGuard;
413 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
414 if (IsInserted() && nFormatIndex < pFormats->size())
415 return pFormats->findByIndex(nFormatIndex)->GetName();
417 return OUString();
420 void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
422 SolarMutexGuard aGuard;
423 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
425 sal_uInt16 nDummy;
426 if (!IsInserted() || nFormatIndex >= pFormats->size() ||
427 lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
429 // not inserted or name exists
430 throw uno::RuntimeException();
433 ScAutoFormat::iterator it = pFormats->begin();
434 std::advance(it, nFormatIndex);
435 ScAutoFormatData *const pData = it->second.get();
436 assert(pData && "AutoFormat data not available");
438 std::unique_ptr<ScAutoFormatData> pNew(new ScAutoFormatData(*pData));
439 pNew->SetName( aNewName );
441 pFormats->erase(it);
442 it = pFormats->insert(std::move(pNew));
443 if (it != pFormats->end())
445 ScAutoFormat::iterator itBeg = pFormats->begin();
446 nFormatIndex = std::distance(itBeg, it);
448 //! notify to other objects
449 pFormats->SetSaveLater(true);
451 else
453 OSL_FAIL("AutoFormat could not be inserted");
454 nFormatIndex = 0; //! old index invalid
458 // beans::XPropertySet
460 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo()
462 SolarMutexGuard aGuard;
463 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
464 return aRef;
467 void SAL_CALL ScAutoFormatObj::setPropertyValue(
468 const OUString& aPropertyName, const uno::Any& aValue )
470 SolarMutexGuard aGuard;
471 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
472 if (!(IsInserted() && nFormatIndex < pFormats->size()))
473 return;
475 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
476 OSL_ENSURE(pData,"AutoFormat data not available");
478 bool bBool = false;
479 if (aPropertyName == SC_UNONAME_INCBACK && (aValue >>= bBool))
480 pData->SetIncludeBackground( bBool );
481 else if (aPropertyName == SC_UNONAME_INCBORD && (aValue >>= bBool))
482 pData->SetIncludeFrame( bBool );
483 else if (aPropertyName == SC_UNONAME_INCFONT && (aValue >>= bBool))
484 pData->SetIncludeFont( bBool );
485 else if (aPropertyName == SC_UNONAME_INCJUST && (aValue >>= bBool))
486 pData->SetIncludeJustify( bBool );
487 else if (aPropertyName == SC_UNONAME_INCNUM && (aValue >>= bBool))
488 pData->SetIncludeValueFormat( bBool );
489 else if (aPropertyName == SC_UNONAME_INCWIDTH && (aValue >>= bBool))
490 pData->SetIncludeWidthHeight( bBool );
492 // else error
494 //! notify to other objects
495 pFormats->SetSaveLater(true);
498 uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const OUString& aPropertyName )
500 SolarMutexGuard aGuard;
501 uno::Any aAny;
503 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
504 if (IsInserted() && nFormatIndex < pFormats->size())
506 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
507 assert(pData && "AutoFormat data not available");
509 bool bValue;
510 bool bError = false;
512 if (aPropertyName == SC_UNONAME_INCBACK)
513 bValue = pData->GetIncludeBackground();
514 else if (aPropertyName == SC_UNONAME_INCBORD)
515 bValue = pData->GetIncludeFrame();
516 else if (aPropertyName == SC_UNONAME_INCFONT)
517 bValue = pData->GetIncludeFont();
518 else if (aPropertyName == SC_UNONAME_INCJUST)
519 bValue = pData->GetIncludeJustify();
520 else if (aPropertyName == SC_UNONAME_INCNUM)
521 bValue = pData->GetIncludeValueFormat();
522 else if (aPropertyName == SC_UNONAME_INCWIDTH)
523 bValue = pData->GetIncludeWidthHeight();
524 else
525 bError = true; // unknown property
527 if (!bError)
528 aAny <<= bValue;
531 return aAny;
534 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj )
536 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) :
537 aPropSet( lcl_GetAutoFieldMap() ),
538 nFormatIndex( nFormat ),
539 nFieldIndex( nField )
543 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
547 // beans::XPropertySet
549 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
551 SolarMutexGuard aGuard;
552 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
553 return aRef;
556 void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
557 const OUString& aPropertyName, const uno::Any& aValue )
559 SolarMutexGuard aGuard;
560 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
561 const SfxItemPropertyMapEntry* pEntry =
562 aPropSet.getPropertyMap().getByName( aPropertyName );
564 if ( !(pEntry && pEntry->nWID && nFormatIndex < pFormats->size()) )
565 return;
567 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
569 if ( IsScItemWid( pEntry->nWID ) )
571 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
573 bool bDone = false;
575 switch( pEntry->nWID )
577 case ATTR_STACKED:
579 table::CellOrientation eOrient;
580 if( aValue >>= eOrient )
582 switch( eOrient )
584 case table::CellOrientation_STANDARD:
585 pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
586 break;
587 case table::CellOrientation_TOPBOTTOM:
588 pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
589 pData->PutItem( nFieldIndex, ScRotateValueItem( 27000_deg100 ) );
590 break;
591 case table::CellOrientation_BOTTOMTOP:
592 pData->PutItem( nFieldIndex, ScVerticalStackCell( false ) );
593 pData->PutItem( nFieldIndex, ScRotateValueItem( 9000_deg100 ) );
594 break;
595 case table::CellOrientation_STACKED:
596 pData->PutItem( nFieldIndex, ScVerticalStackCell( true ) );
597 break;
598 default:
600 // added to avoid warnings
603 bDone = true;
606 break;
607 default:
608 std::unique_ptr<SfxPoolItem> pNewItem(pItem->Clone());
609 bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
610 if (bDone)
611 pData->PutItem( nFieldIndex, *pNewItem );
614 if (bDone)
615 //! Notify to other objects?
616 pFormats->SetSaveLater(true);
619 else
621 switch (pEntry->nWID)
623 case SC_WID_UNO_TBLBORD:
625 table::TableBorder aBorder;
626 if ( aValue >>= aBorder ) // empty = nothing to do
628 SvxBoxItem aOuter(ATTR_BORDER);
629 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
630 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
631 pData->PutItem( nFieldIndex, aOuter );
633 //! Notify for other objects?
634 pFormats->SetSaveLater(true);
637 break;
638 case SC_WID_UNO_TBLBORD2:
640 table::TableBorder2 aBorder2;
641 if ( aValue >>= aBorder2 ) // empty = nothing to do
643 SvxBoxItem aOuter(ATTR_BORDER);
644 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
645 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder2 );
646 pData->PutItem( nFieldIndex, aOuter );
648 //! Notify for other objects?
649 pFormats->SetSaveLater(true);
652 break;
657 uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const OUString& aPropertyName )
659 SolarMutexGuard aGuard;
660 uno::Any aVal;
662 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
663 const SfxItemPropertyMapEntry* pEntry =
664 aPropSet.getPropertyMap().getByName( aPropertyName );
666 if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
668 const ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
670 if ( IsScItemWid( pEntry->nWID ) )
672 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
674 switch( pEntry->nWID )
676 case ATTR_STACKED:
678 const ScRotateValueItem* pRotItem = pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE );
679 Degree100 nRot = pRotItem ? pRotItem->GetValue() : 0_deg100;
680 bool bStacked = static_cast<const ScVerticalStackCell*>(pItem)->GetValue();
681 SvxOrientationItem( nRot, bStacked, TypedWhichId<SvxOrientationItem>(0) ).QueryValue( aVal );
683 break;
684 default:
685 pItem->QueryValue( aVal, pEntry->nMemberId );
689 else
691 switch (pEntry->nWID)
693 case SC_WID_UNO_TBLBORD:
694 case SC_WID_UNO_TBLBORD2:
696 const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
697 if (pItem)
699 SvxBoxItem aOuter(*static_cast<const SvxBoxItem*>(pItem));
700 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
702 if (pEntry->nWID == SC_WID_UNO_TBLBORD2)
703 ScHelperFunctions::AssignTableBorder2ToAny( aVal, aOuter, aInner);
704 else
705 ScHelperFunctions::AssignTableBorderToAny( aVal, aOuter, aInner);
708 break;
713 return aVal;
716 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
718 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */