fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / unoobj / afmtuno.cxx
blobab104f4a9ab08d6b35def1eee7eaff12ec2122e0
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.hrc>
22 #include <svl/poolitem.hxx>
23 #include <vcl/svapp.hxx>
24 #include <svx/unomid.hxx>
25 #include "unowids.hxx"
26 #include <comphelper/servicehelper.hxx>
27 #include <com/sun/star/table/BorderLine.hpp>
28 #include <com/sun/star/table/CellVertJustify2.hpp>
29 #include <com/sun/star/table/ShadowLocation.hpp>
30 #include <com/sun/star/table/TableBorder.hpp>
31 #include <com/sun/star/table/ShadowFormat.hpp>
32 #include <com/sun/star/table/CellRangeAddress.hpp>
33 #include <com/sun/star/table/CellContentType.hpp>
34 #include <com/sun/star/table/TableOrientation.hpp>
35 #include <com/sun/star/table/CellHoriJustify.hpp>
36 #include <com/sun/star/util/SortField.hpp>
37 #include <com/sun/star/util/SortFieldType.hpp>
38 #include <com/sun/star/table/CellOrientation.hpp>
39 #include <com/sun/star/table/CellAddress.hpp>
40 #include <com/sun/star/awt/SimpleFontMetric.hpp>
41 #include <com/sun/star/awt/FontWeight.hpp>
42 #include <com/sun/star/awt/FontSlant.hpp>
43 #include <com/sun/star/awt/CharSet.hpp>
44 #include <com/sun/star/awt/FontDescriptor.hpp>
45 #include <com/sun/star/awt/FontWidth.hpp>
46 #include <com/sun/star/awt/XFont.hpp>
47 #include <com/sun/star/awt/FontType.hpp>
48 #include <com/sun/star/awt/FontUnderline.hpp>
49 #include <com/sun/star/awt/FontStrikeout.hpp>
50 #include <com/sun/star/awt/FontFamily.hpp>
51 #include <com/sun/star/awt/FontPitch.hpp>
53 #include "afmtuno.hxx"
54 #include "miscuno.hxx"
55 #include "autoform.hxx"
56 #include "scdll.hxx"
57 #include "unonames.hxx"
58 #include "cellsuno.hxx"
60 using namespace ::com::sun::star;
62 // ein AutoFormat hat immer 16 Eintraege
63 #define SC_AF_FIELD_COUNT 16
65 // AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs
67 static const SfxItemPropertyMapEntry* lcl_GetAutoFormatMap()
69 static const SfxItemPropertyMapEntry aAutoFormatMap_Impl[] =
71 { OUString(SC_UNONAME_INCBACK), 0, cppu::UnoType<bool>::get(), 0, 0 },
72 { OUString(SC_UNONAME_INCBORD), 0, cppu::UnoType<bool>::get(), 0, 0 },
73 { OUString(SC_UNONAME_INCFONT), 0, cppu::UnoType<bool>::get(), 0, 0 },
74 { OUString(SC_UNONAME_INCJUST), 0, cppu::UnoType<bool>::get(), 0, 0 },
75 { OUString(SC_UNONAME_INCNUM), 0, cppu::UnoType<bool>::get(), 0, 0 },
76 { OUString(SC_UNONAME_INCWIDTH), 0, cppu::UnoType<bool>::get(), 0, 0 },
77 { OUString(), 0, css::uno::Type(), 0, 0 }
79 return aAutoFormatMap_Impl;
82 //! Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly)
83 //! table::TableBorder ??!?
85 static const SfxItemPropertyMapEntry* lcl_GetAutoFieldMap()
87 static const SfxItemPropertyMapEntry aAutoFieldMap_Impl[] =
89 {OUString(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, ::cppu::UnoType<sal_Int32>::get(), 0, MID_BACK_COLOR },
90 {OUString(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
91 {OUString(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, cppu::UnoType<bool>::get(), 0, 0 },
92 {OUString(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT, cppu::UnoType<bool>::get(), 0, MID_CROSSED_OUT },
93 {OUString(SC_UNONAME_CFONT), ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
94 {OUString(SC_UNONAME_CFCHARS), ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
95 {OUString(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
96 {OUString(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_CHAR_SET },
97 {OUString(SC_UNONAME_CFFAMIL), ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
98 {OUString(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
99 {OUString(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_FAMILY },
100 {OUString(SC_UNONAME_CFNAME), ATTR_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
101 {OUString(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
102 {OUString(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_FAMILY_NAME },
103 {OUString(SC_UNONAME_CFPITCH), ATTR_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
104 {OUString(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
105 {OUString(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, ::cppu::UnoType<sal_Int16>::get(), 0, MID_FONT_PITCH },
106 {OUString(SC_UNONAME_CFSTYLE), ATTR_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
107 {OUString(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
108 {OUString(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, ::cppu::UnoType<OUString>::get(), 0, MID_FONT_STYLE_NAME },
109 {OUString(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
110 {OUString(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
111 {OUString(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT, ::cppu::UnoType<float>::get(), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
112 {OUString(SC_UNONAME_COVER), ATTR_FONT_OVERLINE, ::cppu::UnoType<sal_Int16>::get(), 0, MID_TL_STYLE },
113 {OUString(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
114 {OUString(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
115 {OUString(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE, ::cppu::UnoType<awt::FontSlant>::get(), 0, MID_POSTURE },
116 {OUString(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, cppu::UnoType<bool>::get(), 0, 0 },
117 {OUString(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, ::cppu::UnoType<table::TableBorder>::get(), 0, 0 | CONVERT_TWIPS },
118 {OUString(SC_UNONAME_TBLBORD2), SC_WID_UNO_TBLBORD2, ::cppu::UnoType<table::TableBorder2>::get(), 0, 0 | CONVERT_TWIPS },
119 {OUString(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE, ::cppu::UnoType<sal_Int16>::get(), 0, MID_TL_STYLE },
120 {OUString(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
121 {OUString(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
122 {OUString(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT, ::cppu::UnoType<float>::get(), 0, MID_WEIGHT },
123 {OUString(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, ::cppu::UnoType<table::CellHoriJustify>::get(), 0, 0 },
124 {OUString(SC_UNONAME_CELLHJUS_METHOD), ATTR_HOR_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
125 {OUString(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, cppu::UnoType<bool>::get(), 0, MID_GRAPHIC_TRANSPARENT },
126 {OUString(SC_UNONAME_WRAP), ATTR_LINEBREAK, cppu::UnoType<bool>::get(), 0, 0 },
127 {OUString(SC_UNONAME_CELLORI), ATTR_STACKED, ::cppu::UnoType<table::CellOrientation>::get(), 0, 0 },
128 {OUString(SC_UNONAME_PBMARGIN), ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
129 {OUString(SC_UNONAME_PLMARGIN), ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS },
130 {OUString(SC_UNONAME_PRMARGIN), ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS },
131 {OUString(SC_UNONAME_PTMARGIN), ATTR_MARGIN, ::cppu::UnoType<sal_Int32>::get(), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
132 {OUString(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
133 {OUString(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
134 {OUString(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
135 {OUString(SC_UNONAME_CELLVJUS_METHOD), ATTR_VER_JUSTIFY_METHOD, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
136 { OUString(), 0, css::uno::Type(), 0, 0 }
138 return aAutoFieldMap_Impl;
141 #define SCAUTOFORMATSOBJ_SERVICE "com.sun.star.sheet.TableAutoFormats"
143 SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" )
144 SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" )
145 SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, "stardiv.StarCalc.ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE )
147 static bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const OUString& rName, sal_uInt16& rOutIndex )
149 ScAutoFormat::const_iterator itBeg = rFormats.begin(), itEnd = rFormats.end();
150 for (ScAutoFormat::const_iterator it = itBeg; it != itEnd; ++it)
152 const ScAutoFormatData* pEntry = it->second;
153 const OUString& aEntryName = pEntry->GetName();
154 if ( aEntryName.equals(rName) )
156 size_t nPos = std::distance(itBeg, it);
157 rOutIndex = nPos;
158 return true;
161 return false; // is nich
164 ScAutoFormatsObj::ScAutoFormatsObj()
166 //! Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten
167 //! bekannt sein, damit Aenderungen gebroadcasted werden koennen
170 ScAutoFormatsObj::~ScAutoFormatsObj()
174 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* SAL_CALL
175 ScAutoFormatsObj_get_implementation(css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const &)
177 SolarMutexGuard aGuard;
178 ScDLL::Init();
179 return cppu::acquire(new ScAutoFormatsObj);
182 // XTableAutoFormats
184 ScAutoFormatObj* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
186 if (nIndex < ScGlobal::GetOrCreateAutoFormat()->size())
187 return new ScAutoFormatObj(nIndex);
189 return NULL; // falscher Index
192 ScAutoFormatObj* ScAutoFormatsObj::GetObjectByName_Impl(const OUString& aName)
194 OUString aString(aName);
195 sal_uInt16 nIndex;
196 if (lcl_FindAutoFormatIndex(
197 *ScGlobal::GetOrCreateAutoFormat(), aString, nIndex ))
198 return GetObjectByIndex_Impl(nIndex);
199 return NULL;
202 // container::XNameContainer
204 void SAL_CALL ScAutoFormatsObj::insertByName( const OUString& aName, const uno::Any& aElement )
205 throw (lang::IllegalArgumentException, container::ElementExistException,
206 lang::WrappedTargetException, uno::RuntimeException,
207 std::exception)
209 SolarMutexGuard aGuard;
210 bool bDone = false;
211 // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein...
212 uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY);
213 if ( xInterface.is() )
215 ScAutoFormatObj* pFormatObj = ScAutoFormatObj::getImplementation( xInterface );
216 if ( pFormatObj && !pFormatObj->IsInserted() ) // noch nicht eingefuegt?
218 OUString aNameStr(aName);
219 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
221 sal_uInt16 nDummy;
222 if (!lcl_FindAutoFormatIndex( *pFormats, aNameStr, nDummy ))
224 ScAutoFormatData* pNew = new ScAutoFormatData();
225 pNew->SetName( aNameStr );
227 if (pFormats->insert(pNew))
229 //! Notify fuer andere Objekte
230 pFormats->Save(); // sofort speichern
232 sal_uInt16 nNewIndex;
233 if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nNewIndex ))
235 pFormatObj->InitFormat( nNewIndex ); // kann jetzt benutzt werden
236 bDone = true;
239 else
241 OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
242 throw uno::RuntimeException();
245 else
247 throw container::ElementExistException();
252 if (!bDone)
254 // other errors are handled above
255 throw lang::IllegalArgumentException();
259 void SAL_CALL ScAutoFormatsObj::replaceByName( const OUString& aName, const uno::Any& aElement )
260 throw(lang::IllegalArgumentException, container::NoSuchElementException,
261 lang::WrappedTargetException, uno::RuntimeException, std::exception)
263 SolarMutexGuard aGuard;
264 //! zusammenfassen?
265 removeByName( aName );
266 insertByName( aName, aElement );
269 void SAL_CALL ScAutoFormatsObj::removeByName( const OUString& aName )
270 throw(container::NoSuchElementException,
271 lang::WrappedTargetException, uno::RuntimeException, std::exception)
273 SolarMutexGuard aGuard;
274 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
276 ScAutoFormat::iterator it = pFormats->find(aName);
277 if (it != pFormats->end())
279 pFormats->erase(it);
281 //! Notify fuer andere Objekte
282 pFormats->Save(); // sofort speichern
284 else
286 throw container::NoSuchElementException();
290 // container::XEnumerationAccess
292 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
293 throw(uno::RuntimeException, std::exception)
295 SolarMutexGuard aGuard;
296 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableAutoFormatEnumeration"));
299 // container::XIndexAccess
301 sal_Int32 SAL_CALL ScAutoFormatsObj::getCount() throw(uno::RuntimeException, std::exception)
303 SolarMutexGuard aGuard;
304 return ScGlobal::GetOrCreateAutoFormat()->size();
307 uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
308 throw(lang::IndexOutOfBoundsException,
309 lang::WrappedTargetException, uno::RuntimeException, std::exception)
311 SolarMutexGuard aGuard;
312 uno::Reference< container::XNamed > xFormat(GetObjectByIndex_Impl((sal_uInt16)nIndex));
313 if (!xFormat.is())
314 throw lang::IndexOutOfBoundsException();
315 return uno::makeAny(xFormat);
318 uno::Type SAL_CALL ScAutoFormatsObj::getElementType() throw(uno::RuntimeException, std::exception)
320 SolarMutexGuard aGuard;
321 return cppu::UnoType<container::XNamed>::get(); // muss zu getByIndex passen
324 sal_Bool SAL_CALL ScAutoFormatsObj::hasElements() throw(uno::RuntimeException, std::exception)
326 SolarMutexGuard aGuard;
327 return ( getCount() != 0 );
330 // container::XNameAccess
332 uno::Any SAL_CALL ScAutoFormatsObj::getByName( const OUString& aName )
333 throw(container::NoSuchElementException,
334 lang::WrappedTargetException, uno::RuntimeException, std::exception)
336 SolarMutexGuard aGuard;
337 uno::Reference< container::XNamed > xFormat(GetObjectByName_Impl(aName));
338 if (!xFormat.is())
339 throw container::NoSuchElementException();
340 return uno::makeAny(xFormat);
343 uno::Sequence<OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
344 throw(uno::RuntimeException, std::exception)
346 SolarMutexGuard aGuard;
347 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
348 uno::Sequence<OUString> aSeq(pFormats->size());
349 OUString* pAry = aSeq.getArray();
350 ScAutoFormat::const_iterator it = pFormats->begin(), itEnd = pFormats->end();
351 for (size_t i = 0; it != itEnd; ++it, ++i)
353 pAry[i] = it->second->GetName();
355 return aSeq;
358 sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const OUString& aName )
359 throw(uno::RuntimeException, std::exception)
361 SolarMutexGuard aGuard;
362 OUString aString(aName);
363 sal_uInt16 nDummy;
364 return lcl_FindAutoFormatIndex(
365 *ScGlobal::GetOrCreateAutoFormat(), aString, nDummy );
368 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
369 aPropSet( lcl_GetAutoFormatMap() ),
370 nFormatIndex( nIndex )
372 //! Listening !!!
375 ScAutoFormatObj::~ScAutoFormatObj()
377 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
378 // gespeichert, damit sie z.B. im Writer sichtbar sind
380 if (IsInserted())
382 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
383 if ( pFormats && pFormats->IsSaveLater() )
384 pFormats->Save();
386 // Save() setzt SaveLater Flag zurueck
390 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex )
392 OSL_ENSURE( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat mehrfach" );
393 nFormatIndex = nNewIndex;
394 //! Listening !!!
397 // XUnoTunnel
399 sal_Int64 SAL_CALL ScAutoFormatObj::getSomething(
400 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException, std::exception)
402 if ( rId.getLength() == 16 &&
403 0 == memcmp( getUnoTunnelId().getConstArray(),
404 rId.getConstArray(), 16 ) )
406 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
408 return 0;
411 namespace
413 class theScAutoFormatObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScAutoFormatObjUnoTunnelId> {};
416 const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId()
418 return theScAutoFormatObjUnoTunnelId::get().getSeq();
421 ScAutoFormatObj* ScAutoFormatObj::getImplementation(const uno::Reference<uno::XInterface>& rObj)
423 ScAutoFormatObj* pRet = NULL;
424 uno::Reference<lang::XUnoTunnel> xUT(rObj, uno::UNO_QUERY);
425 if (xUT.is())
426 pRet = reinterpret_cast<ScAutoFormatObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
427 return pRet;
430 void ScAutoFormatObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
432 // spaeter...
435 // XTableAutoFormat
437 ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
439 if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
440 return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
442 return NULL;
445 // container::XEnumerationAccess
447 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
448 throw(uno::RuntimeException, std::exception)
450 SolarMutexGuard aGuard;
451 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableAutoFormatEnumeration"));
454 // container::XIndexAccess
456 sal_Int32 SAL_CALL ScAutoFormatObj::getCount() throw(uno::RuntimeException, std::exception)
458 SolarMutexGuard aGuard;
459 if (IsInserted())
460 return SC_AF_FIELD_COUNT; // immer 16 Elemente
461 else
462 return 0;
465 uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
466 throw(lang::IndexOutOfBoundsException,
467 lang::WrappedTargetException, uno::RuntimeException, std::exception)
469 SolarMutexGuard aGuard;
471 if ( nIndex < 0 || nIndex >= getCount() )
472 throw lang::IndexOutOfBoundsException();
474 if (IsInserted())
475 return uno::makeAny(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl((sal_uInt16)nIndex)));
476 return uno::Any();
479 uno::Type SAL_CALL ScAutoFormatObj::getElementType() throw(uno::RuntimeException, std::exception)
481 SolarMutexGuard aGuard;
482 return cppu::UnoType<beans::XPropertySet>::get(); // muss zu getByIndex passen
485 sal_Bool SAL_CALL ScAutoFormatObj::hasElements() throw(uno::RuntimeException, std::exception)
487 SolarMutexGuard aGuard;
488 return ( getCount() != 0 );
491 // container::XNamed
493 OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException, std::exception)
495 SolarMutexGuard aGuard;
496 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
497 if (IsInserted() && nFormatIndex < pFormats->size())
498 return pFormats->findByIndex(nFormatIndex)->GetName();
500 return OUString();
503 void SAL_CALL ScAutoFormatObj::setName( const OUString& aNewName )
504 throw (uno::RuntimeException, std::exception)
506 SolarMutexGuard aGuard;
507 OUString aNewString(aNewName);
508 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
510 sal_uInt16 nDummy;
511 if (IsInserted() && nFormatIndex < pFormats->size() &&
512 !lcl_FindAutoFormatIndex( *pFormats, aNewName, nDummy ))
514 ScAutoFormat::iterator it = pFormats->begin();
515 std::advance(it, nFormatIndex);
516 ScAutoFormatData* pData = it->second;
517 OSL_ENSURE(pData,"AutoFormat Daten nicht da");
519 ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
520 pNew->SetName( aNewString );
522 pFormats->erase(it);
523 if (pFormats->insert(pNew))
525 it = pFormats->find(pNew);
526 ScAutoFormat::iterator itBeg = pFormats->begin();
527 nFormatIndex = std::distance(itBeg, it);
529 //! Notify fuer andere Objekte
530 pFormats->SetSaveLater(true);
532 else
534 OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
535 nFormatIndex = 0; //! alter Index ist ungueltig
538 else
540 // not inserted or name exists
541 throw uno::RuntimeException();
545 // beans::XPropertySet
547 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo()
548 throw(uno::RuntimeException, std::exception)
550 SolarMutexGuard aGuard;
551 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
552 return aRef;
555 void SAL_CALL ScAutoFormatObj::setPropertyValue(
556 const OUString& aPropertyName, const uno::Any& aValue )
557 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
558 lang::IllegalArgumentException, lang::WrappedTargetException,
559 uno::RuntimeException, std::exception)
561 SolarMutexGuard aGuard;
562 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
563 if (IsInserted() && nFormatIndex < pFormats->size())
565 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
566 OSL_ENSURE(pData,"AutoFormat Daten nicht da");
568 OUString aPropString(aPropertyName);
569 bool bBool;
570 if (aPropString == SC_UNONAME_INCBACK && (aValue >>= bBool))
571 pData->SetIncludeBackground( bBool );
572 else if (aPropString == SC_UNONAME_INCBORD && (aValue >>= bBool))
573 pData->SetIncludeFrame( bBool );
574 else if (aPropString == SC_UNONAME_INCFONT && (aValue >>= bBool))
575 pData->SetIncludeFont( bBool );
576 else if (aPropString == SC_UNONAME_INCJUST && (aValue >>= bBool))
577 pData->SetIncludeJustify( bBool );
578 else if (aPropString == SC_UNONAME_INCNUM && (aValue >>= bBool))
579 pData->SetIncludeValueFormat( bBool );
580 else if (aPropString == SC_UNONAME_INCWIDTH && (aValue >>= bBool))
581 pData->SetIncludeWidthHeight( bBool );
583 // else Fehler
585 //! Notify fuer andere Objekte
586 pFormats->SetSaveLater(true);
590 uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const OUString& aPropertyName )
591 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
592 uno::RuntimeException, std::exception)
594 SolarMutexGuard aGuard;
595 uno::Any aAny;
597 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
598 if (IsInserted() && nFormatIndex < pFormats->size())
600 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
601 OSL_ENSURE(pData,"AutoFormat Daten nicht da");
603 bool bValue;
604 bool bError = false;
606 if (aPropertyName == SC_UNONAME_INCBACK)
607 bValue = pData->GetIncludeBackground();
608 else if (aPropertyName == SC_UNONAME_INCBORD)
609 bValue = pData->GetIncludeFrame();
610 else if (aPropertyName == SC_UNONAME_INCFONT)
611 bValue = pData->GetIncludeFont();
612 else if (aPropertyName == SC_UNONAME_INCJUST)
613 bValue = pData->GetIncludeJustify();
614 else if (aPropertyName == SC_UNONAME_INCNUM)
615 bValue = pData->GetIncludeValueFormat();
616 else if (aPropertyName == SC_UNONAME_INCWIDTH)
617 bValue = pData->GetIncludeWidthHeight();
618 else
619 bError = true; // unbekannte Property
621 if (!bError)
622 aAny <<= bValue;
625 return aAny;
628 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj )
630 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) :
631 aPropSet( lcl_GetAutoFieldMap() ),
632 nFormatIndex( nFormat ),
633 nFieldIndex( nField )
635 //! Listening !!!
638 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
642 void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
644 // spaeter...
647 // beans::XPropertySet
649 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
650 throw(uno::RuntimeException, std::exception)
652 SolarMutexGuard aGuard;
653 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
654 return aRef;
657 void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
658 const OUString& aPropertyName, const uno::Any& aValue )
659 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
660 lang::IllegalArgumentException, lang::WrappedTargetException,
661 uno::RuntimeException, std::exception)
663 SolarMutexGuard aGuard;
664 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
665 const SfxItemPropertySimpleEntry* pEntry =
666 aPropSet.getPropertyMap().getByName( aPropertyName );
668 if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
670 ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
672 if ( IsScItemWid( pEntry->nWID ) )
674 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
676 bool bDone = false;
678 switch( pEntry->nWID )
680 case ATTR_STACKED:
682 table::CellOrientation eOrient;
683 if( aValue >>= eOrient )
685 switch( eOrient )
687 case table::CellOrientation_STANDARD:
688 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, false ) );
689 break;
690 case table::CellOrientation_TOPBOTTOM:
691 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, false ) );
692 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
693 break;
694 case table::CellOrientation_BOTTOMTOP:
695 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, false ) );
696 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
697 break;
698 case table::CellOrientation_STACKED:
699 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, true ) );
700 break;
701 default:
703 // added to avoid warnings
706 bDone = true;
709 break;
710 default:
711 SfxPoolItem* pNewItem = pItem->Clone();
712 bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
713 if (bDone)
714 pData->PutItem( nFieldIndex, *pNewItem );
715 delete pNewItem;
718 if (bDone)
719 //! Notify fuer andere Objekte?
720 pFormats->SetSaveLater(true);
723 else
725 switch (pEntry->nWID)
727 case SC_WID_UNO_TBLBORD:
729 table::TableBorder aBorder;
730 if ( aValue >>= aBorder ) // empty = nothing to do
732 SvxBoxItem aOuter(ATTR_BORDER);
733 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
734 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
735 pData->PutItem( nFieldIndex, aOuter );
737 //! Notify for other objects?
738 pFormats->SetSaveLater(true);
741 break;
742 case SC_WID_UNO_TBLBORD2:
744 table::TableBorder2 aBorder2;
745 if ( aValue >>= aBorder2 ) // empty = nothing to do
747 SvxBoxItem aOuter(ATTR_BORDER);
748 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
749 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder2 );
750 pData->PutItem( nFieldIndex, aOuter );
752 //! Notify for other objects?
753 pFormats->SetSaveLater(true);
756 break;
762 uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const OUString& aPropertyName )
763 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
764 uno::RuntimeException, std::exception)
766 SolarMutexGuard aGuard;
767 uno::Any aVal;
769 ScAutoFormat* pFormats = ScGlobal::GetOrCreateAutoFormat();
770 const SfxItemPropertySimpleEntry* pEntry =
771 aPropSet.getPropertyMap().getByName( aPropertyName );
773 if ( pEntry && pEntry->nWID && nFormatIndex < pFormats->size() )
775 const ScAutoFormatData* pData = pFormats->findByIndex(nFormatIndex);
777 if ( IsScItemWid( pEntry->nWID ) )
779 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
781 switch( pEntry->nWID )
783 case ATTR_STACKED:
785 const SfxInt32Item* pRotItem = static_cast<const SfxInt32Item*>(pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE ));
786 sal_Int32 nRot = pRotItem ? pRotItem->GetValue() : 0;
787 bool bStacked = static_cast<const SfxBoolItem*>(pItem)->GetValue();
788 SvxOrientationItem( nRot, bStacked, 0 ).QueryValue( aVal );
790 break;
791 default:
792 pItem->QueryValue( aVal, pEntry->nMemberId );
796 else
798 switch (pEntry->nWID)
800 case SC_WID_UNO_TBLBORD:
801 case SC_WID_UNO_TBLBORD2:
803 const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
804 if (pItem)
806 SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem)));
807 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
809 if (pEntry->nWID == SC_WID_UNO_TBLBORD2)
810 ScHelperFunctions::AssignTableBorder2ToAny( aVal, aOuter, aInner);
811 else
812 ScHelperFunctions::AssignTableBorderToAny( aVal, aOuter, aInner);
815 break;
820 return aVal;
823 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
825 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */