1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/shl.hxx>
23 #include <svl/poolitem.hxx>
24 #include <vcl/svapp.hxx>
25 #include <svx/unomid.hxx>
26 #include "unowids.hxx"
27 #include <comphelper/servicehelper.hxx>
28 #include <com/sun/star/table/BorderLine.hpp>
29 #include <com/sun/star/table/CellVertJustify2.hpp>
30 #include <com/sun/star/table/ShadowLocation.hpp>
31 #include <com/sun/star/table/TableBorder.hpp>
32 #include <com/sun/star/table/ShadowFormat.hpp>
33 #include <com/sun/star/table/CellRangeAddress.hpp>
34 #include <com/sun/star/table/CellContentType.hpp>
35 #include <com/sun/star/table/TableOrientation.hpp>
36 #include <com/sun/star/table/CellHoriJustify.hpp>
37 #include <com/sun/star/util/SortField.hpp>
38 #include <com/sun/star/util/SortFieldType.hpp>
39 #include <com/sun/star/table/CellOrientation.hpp>
40 #include <com/sun/star/table/CellAddress.hpp>
41 #include <com/sun/star/awt/SimpleFontMetric.hpp>
42 #include <com/sun/star/awt/FontWeight.hpp>
43 #include <com/sun/star/awt/FontSlant.hpp>
44 #include <com/sun/star/awt/CharSet.hpp>
45 #include <com/sun/star/awt/FontDescriptor.hpp>
46 #include <com/sun/star/awt/FontWidth.hpp>
47 #include <com/sun/star/awt/XFont.hpp>
48 #include <com/sun/star/awt/FontType.hpp>
49 #include <com/sun/star/awt/FontUnderline.hpp>
50 #include <com/sun/star/awt/FontStrikeout.hpp>
51 #include <com/sun/star/awt/FontFamily.hpp>
52 #include <com/sun/star/awt/FontPitch.hpp>
54 #include "afmtuno.hxx"
55 #include "miscuno.hxx"
56 #include "autoform.hxx"
58 #include "unonames.hxx"
59 #include "cellsuno.hxx"
61 using namespace ::com::sun::star
;
63 // ein AutoFormat hat immer 16 Eintraege
64 #define SC_AF_FIELD_COUNT 16
66 // AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs
68 static const SfxItemPropertyMapEntry
* lcl_GetAutoFormatMap()
70 static const SfxItemPropertyMapEntry aAutoFormatMap_Impl
[] =
72 { OUString(SC_UNONAME_INCBACK
), 0, ::getBooleanCppuType(), 0, 0 },
73 { OUString(SC_UNONAME_INCBORD
), 0, ::getBooleanCppuType(), 0, 0 },
74 { OUString(SC_UNONAME_INCFONT
), 0, ::getBooleanCppuType(), 0, 0 },
75 { OUString(SC_UNONAME_INCJUST
), 0, ::getBooleanCppuType(), 0, 0 },
76 { OUString(SC_UNONAME_INCNUM
), 0, ::getBooleanCppuType(), 0, 0 },
77 { OUString(SC_UNONAME_INCWIDTH
), 0, ::getBooleanCppuType(), 0, 0 },
78 { OUString(), 0, css::uno::Type(), 0, 0 }
80 return aAutoFormatMap_Impl
;
83 //! Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly)
84 //! table::TableBorder ??!?
86 static const SfxItemPropertyMapEntry
* lcl_GetAutoFieldMap()
88 static const SfxItemPropertyMapEntry aAutoFieldMap_Impl
[] =
90 {OUString(SC_UNONAME_CELLBACK
), ATTR_BACKGROUND
, ::cppu::UnoType
<sal_Int32
>::get(), 0, MID_BACK_COLOR
},
91 {OUString(SC_UNONAME_CCOLOR
), ATTR_FONT_COLOR
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
92 {OUString(SC_UNONAME_COUTL
), ATTR_FONT_CONTOUR
, ::getBooleanCppuType(), 0, 0 },
93 {OUString(SC_UNONAME_CCROSS
), ATTR_FONT_CROSSEDOUT
, ::getBooleanCppuType(), 0, MID_CROSSED_OUT
},
94 {OUString(SC_UNONAME_CFONT
), ATTR_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_FAMILY
},
95 {OUString(SC_UNONAME_CFCHARS
), ATTR_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_CHAR_SET
},
96 {OUString(SC_UNO_CJK_CFCHARS
), ATTR_CJK_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_CHAR_SET
},
97 {OUString(SC_UNO_CTL_CFCHARS
), ATTR_CTL_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_CHAR_SET
},
98 {OUString(SC_UNONAME_CFFAMIL
), ATTR_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_FAMILY
},
99 {OUString(SC_UNO_CJK_CFFAMIL
), ATTR_CJK_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_FAMILY
},
100 {OUString(SC_UNO_CTL_CFFAMIL
), ATTR_CTL_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_FAMILY
},
101 {OUString(SC_UNONAME_CFNAME
), ATTR_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_FAMILY_NAME
},
102 {OUString(SC_UNO_CJK_CFNAME
), ATTR_CJK_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_FAMILY_NAME
},
103 {OUString(SC_UNO_CTL_CFNAME
), ATTR_CTL_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_FAMILY_NAME
},
104 {OUString(SC_UNONAME_CFPITCH
), ATTR_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_PITCH
},
105 {OUString(SC_UNO_CJK_CFPITCH
), ATTR_CJK_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_PITCH
},
106 {OUString(SC_UNO_CTL_CFPITCH
), ATTR_CTL_FONT
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_FONT_PITCH
},
107 {OUString(SC_UNONAME_CFSTYLE
), ATTR_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_STYLE_NAME
},
108 {OUString(SC_UNO_CJK_CFSTYLE
), ATTR_CJK_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_STYLE_NAME
},
109 {OUString(SC_UNO_CTL_CFSTYLE
), ATTR_CTL_FONT
, ::cppu::UnoType
<OUString
>::get(), 0, MID_FONT_STYLE_NAME
},
110 {OUString(SC_UNONAME_CHEIGHT
), ATTR_FONT_HEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
111 {OUString(SC_UNO_CJK_CHEIGHT
), ATTR_CJK_FONT_HEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
112 {OUString(SC_UNO_CTL_CHEIGHT
), ATTR_CTL_FONT_HEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
113 {OUString(SC_UNONAME_COVER
), ATTR_FONT_OVERLINE
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_TL_STYLE
},
114 {OUString(SC_UNONAME_CPOST
), ATTR_FONT_POSTURE
, ::cppu::UnoType
<awt::FontSlant
>::get(), 0, MID_POSTURE
},
115 {OUString(SC_UNO_CJK_CPOST
), ATTR_CJK_FONT_POSTURE
, ::cppu::UnoType
<awt::FontSlant
>::get(), 0, MID_POSTURE
},
116 {OUString(SC_UNO_CTL_CPOST
), ATTR_CTL_FONT_POSTURE
, ::cppu::UnoType
<awt::FontSlant
>::get(), 0, MID_POSTURE
},
117 {OUString(SC_UNONAME_CSHADD
), ATTR_FONT_SHADOWED
, ::getBooleanCppuType(), 0, 0 },
118 {OUString(SC_UNONAME_TBLBORD
), SC_WID_UNO_TBLBORD
, ::cppu::UnoType
<table::TableBorder
>::get(), 0, 0 | CONVERT_TWIPS
},
119 {OUString(SC_UNONAME_TBLBORD2
), SC_WID_UNO_TBLBORD2
, ::cppu::UnoType
<table::TableBorder2
>::get(), 0, 0 | CONVERT_TWIPS
},
120 {OUString(SC_UNONAME_CUNDER
), ATTR_FONT_UNDERLINE
, ::cppu::UnoType
<sal_Int16
>::get(), 0, MID_TL_STYLE
},
121 {OUString(SC_UNONAME_CWEIGHT
), ATTR_FONT_WEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_WEIGHT
},
122 {OUString(SC_UNO_CJK_CWEIGHT
), ATTR_CJK_FONT_WEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_WEIGHT
},
123 {OUString(SC_UNO_CTL_CWEIGHT
), ATTR_CTL_FONT_WEIGHT
, ::cppu::UnoType
<float>::get(), 0, MID_WEIGHT
},
124 {OUString(SC_UNONAME_CELLHJUS
), ATTR_HOR_JUSTIFY
, ::cppu::UnoType
<table::CellHoriJustify
>::get(), 0, 0 },
125 {OUString(SC_UNONAME_CELLHJUS_METHOD
), ATTR_HOR_JUSTIFY_METHOD
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
126 {OUString(SC_UNONAME_CELLTRAN
), ATTR_BACKGROUND
, ::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT
},
127 {OUString(SC_UNONAME_WRAP
), ATTR_LINEBREAK
, ::getBooleanCppuType(), 0, 0 },
128 {OUString(SC_UNONAME_CELLORI
), ATTR_STACKED
, ::cppu::UnoType
<table::CellOrientation
>::get(), 0, 0 },
129 {OUString(SC_UNONAME_PBMARGIN
), ATTR_MARGIN
, ::cppu::UnoType
<sal_Int32
>::get(), 0, MID_MARGIN_LO_MARGIN
| CONVERT_TWIPS
},
130 {OUString(SC_UNONAME_PLMARGIN
), ATTR_MARGIN
, ::cppu::UnoType
<sal_Int32
>::get(), 0, MID_MARGIN_L_MARGIN
| CONVERT_TWIPS
},
131 {OUString(SC_UNONAME_PRMARGIN
), ATTR_MARGIN
, ::cppu::UnoType
<sal_Int32
>::get(), 0, MID_MARGIN_R_MARGIN
| CONVERT_TWIPS
},
132 {OUString(SC_UNONAME_PTMARGIN
), ATTR_MARGIN
, ::cppu::UnoType
<sal_Int32
>::get(), 0, MID_MARGIN_UP_MARGIN
| CONVERT_TWIPS
},
133 {OUString(SC_UNONAME_ROTANG
), ATTR_ROTATE_VALUE
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
134 {OUString(SC_UNONAME_ROTREF
), ATTR_ROTATE_MODE
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
135 {OUString(SC_UNONAME_CELLVJUS
), ATTR_VER_JUSTIFY
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
136 {OUString(SC_UNONAME_CELLVJUS_METHOD
), ATTR_VER_JUSTIFY_METHOD
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
137 { OUString(), 0, css::uno::Type(), 0, 0 }
139 return aAutoFieldMap_Impl
;
142 #define SCAUTOFORMATSOBJ_SERVICE "com.sun.star.sheet.TableAutoFormats"
144 SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj
, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" )
145 SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj
, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" )
146 SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj
, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE
)
148 static bool lcl_FindAutoFormatIndex( const ScAutoFormat
& rFormats
, const OUString
& rName
, sal_uInt16
& rOutIndex
)
150 ScAutoFormat::const_iterator itBeg
= rFormats
.begin(), itEnd
= rFormats
.end();
151 for (ScAutoFormat::const_iterator it
= itBeg
; it
!= itEnd
; ++it
)
153 const ScAutoFormatData
* pEntry
= it
->second
;
154 const OUString
& aEntryName
= pEntry
->GetName();
155 if ( aEntryName
.equals(rName
) )
157 size_t nPos
= std::distance(itBeg
, it
);
162 return false; // is nich
165 ScAutoFormatsObj::ScAutoFormatsObj()
167 //! Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten
168 //! bekannt sein, damit Aenderungen gebroadcasted werden koennen
171 ScAutoFormatsObj::~ScAutoFormatsObj()
175 // stuff for exService_...
177 uno::Reference
<uno::XInterface
> SAL_CALL
ScAutoFormatsObj_CreateInstance(
178 const uno::Reference
<lang::XMultiServiceFactory
>& )
180 SolarMutexGuard aGuard
;
182 static uno::Reference
< uno::XInterface
> xInst((::cppu::OWeakObject
*) new ScAutoFormatsObj
);
186 OUString
ScAutoFormatsObj::getImplementationName_Static()
188 return OUString( "stardiv.StarCalc.ScAutoFormatsObj" );
191 uno::Sequence
<OUString
> ScAutoFormatsObj::getSupportedServiceNames_Static()
193 uno::Sequence
<OUString
> aRet(1);
194 OUString
* pArray
= aRet
.getArray();
195 pArray
[0] = OUString( SCAUTOFORMATSOBJ_SERVICE
);
201 ScAutoFormatObj
* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
203 if (nIndex
< ScGlobal::GetOrCreateAutoFormat()->size())
204 return new ScAutoFormatObj(nIndex
);
206 return NULL
; // falscher Index
209 ScAutoFormatObj
* ScAutoFormatsObj::GetObjectByName_Impl(const OUString
& aName
)
211 OUString
aString(aName
);
213 if (lcl_FindAutoFormatIndex(
214 *ScGlobal::GetOrCreateAutoFormat(), aString
, nIndex
))
215 return GetObjectByIndex_Impl(nIndex
);
219 // container::XNameContainer
221 void SAL_CALL
ScAutoFormatsObj::insertByName( const OUString
& aName
, const uno::Any
& aElement
)
222 throw (lang::IllegalArgumentException
, container::ElementExistException
,
223 lang::WrappedTargetException
, uno::RuntimeException
,
226 SolarMutexGuard aGuard
;
228 // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein...
229 uno::Reference
< uno::XInterface
> xInterface(aElement
, uno::UNO_QUERY
);
230 if ( xInterface
.is() )
232 ScAutoFormatObj
* pFormatObj
= ScAutoFormatObj::getImplementation( xInterface
);
233 if ( pFormatObj
&& !pFormatObj
->IsInserted() ) // noch nicht eingefuegt?
235 OUString
aNameStr(aName
);
236 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
239 if (!lcl_FindAutoFormatIndex( *pFormats
, aNameStr
, nDummy
))
241 ScAutoFormatData
* pNew
= new ScAutoFormatData();
242 pNew
->SetName( aNameStr
);
244 if (pFormats
->insert(pNew
))
246 //! Notify fuer andere Objekte
247 pFormats
->Save(); // sofort speichern
249 sal_uInt16 nNewIndex
;
250 if (lcl_FindAutoFormatIndex( *pFormats
, aNameStr
, nNewIndex
))
252 pFormatObj
->InitFormat( nNewIndex
); // kann jetzt benutzt werden
258 OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
259 throw uno::RuntimeException();
264 throw container::ElementExistException();
271 // other errors are handled above
272 throw lang::IllegalArgumentException();
276 void SAL_CALL
ScAutoFormatsObj::replaceByName( const OUString
& aName
, const uno::Any
& aElement
)
277 throw(lang::IllegalArgumentException
, container::NoSuchElementException
,
278 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
280 SolarMutexGuard aGuard
;
282 removeByName( aName
);
283 insertByName( aName
, aElement
);
286 void SAL_CALL
ScAutoFormatsObj::removeByName( const OUString
& aName
)
287 throw(container::NoSuchElementException
,
288 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
290 SolarMutexGuard aGuard
;
291 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
293 ScAutoFormat::iterator it
= pFormats
->find(aName
);
294 if (it
!= pFormats
->end())
298 //! Notify fuer andere Objekte
299 pFormats
->Save(); // sofort speichern
303 throw container::NoSuchElementException();
307 // container::XEnumerationAccess
309 uno::Reference
<container::XEnumeration
> SAL_CALL
ScAutoFormatsObj::createEnumeration()
310 throw(uno::RuntimeException
, std::exception
)
312 SolarMutexGuard aGuard
;
313 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableAutoFormatEnumeration"));
316 // container::XIndexAccess
318 sal_Int32 SAL_CALL
ScAutoFormatsObj::getCount() throw(uno::RuntimeException
, std::exception
)
320 SolarMutexGuard aGuard
;
321 return ScGlobal::GetOrCreateAutoFormat()->size();
324 uno::Any SAL_CALL
ScAutoFormatsObj::getByIndex( sal_Int32 nIndex
)
325 throw(lang::IndexOutOfBoundsException
,
326 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
328 SolarMutexGuard aGuard
;
329 uno::Reference
< container::XNamed
> xFormat(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
331 throw lang::IndexOutOfBoundsException();
332 return uno::makeAny(xFormat
);
335 uno::Type SAL_CALL
ScAutoFormatsObj::getElementType() throw(uno::RuntimeException
, std::exception
)
337 SolarMutexGuard aGuard
;
338 return cppu::UnoType
<container::XNamed
>::get(); // muss zu getByIndex passen
341 sal_Bool SAL_CALL
ScAutoFormatsObj::hasElements() throw(uno::RuntimeException
, std::exception
)
343 SolarMutexGuard aGuard
;
344 return ( getCount() != 0 );
347 // container::XNameAccess
349 uno::Any SAL_CALL
ScAutoFormatsObj::getByName( const OUString
& aName
)
350 throw(container::NoSuchElementException
,
351 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
353 SolarMutexGuard aGuard
;
354 uno::Reference
< container::XNamed
> xFormat(GetObjectByName_Impl(aName
));
356 throw container::NoSuchElementException();
357 return uno::makeAny(xFormat
);
360 uno::Sequence
<OUString
> SAL_CALL
ScAutoFormatsObj::getElementNames()
361 throw(uno::RuntimeException
, std::exception
)
363 SolarMutexGuard aGuard
;
364 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
365 uno::Sequence
<OUString
> aSeq(pFormats
->size());
366 OUString
* pAry
= aSeq
.getArray();
367 ScAutoFormat::const_iterator it
= pFormats
->begin(), itEnd
= pFormats
->end();
368 for (size_t i
= 0; it
!= itEnd
; ++it
, ++i
)
370 pAry
[i
] = it
->second
->GetName();
375 sal_Bool SAL_CALL
ScAutoFormatsObj::hasByName( const OUString
& aName
)
376 throw(uno::RuntimeException
, std::exception
)
378 SolarMutexGuard aGuard
;
379 OUString
aString(aName
);
381 return lcl_FindAutoFormatIndex(
382 *ScGlobal::GetOrCreateAutoFormat(), aString
, nDummy
);
385 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex
) :
386 aPropSet( lcl_GetAutoFormatMap() ),
387 nFormatIndex( nIndex
)
392 ScAutoFormatObj::~ScAutoFormatObj()
394 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
395 // gespeichert, damit sie z.B. im Writer sichtbar sind
399 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
400 if ( pFormats
&& pFormats
->IsSaveLater() )
403 // Save() setzt SaveLater Flag zurueck
407 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex
)
409 OSL_ENSURE( nFormatIndex
== SC_AFMTOBJ_INVALID
, "ScAutoFormatObj::InitFormat mehrfach" );
410 nFormatIndex
= nNewIndex
;
416 sal_Int64 SAL_CALL
ScAutoFormatObj::getSomething(
417 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
419 if ( rId
.getLength() == 16 &&
420 0 == memcmp( getUnoTunnelId().getConstArray(),
421 rId
.getConstArray(), 16 ) )
423 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
430 class theScAutoFormatObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScAutoFormatObjUnoTunnelId
> {};
433 const uno::Sequence
<sal_Int8
>& ScAutoFormatObj::getUnoTunnelId()
435 return theScAutoFormatObjUnoTunnelId::get().getSeq();
438 ScAutoFormatObj
* ScAutoFormatObj::getImplementation(
439 const uno::Reference
<uno::XInterface
> xObj
)
441 ScAutoFormatObj
* pRet
= NULL
;
442 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
444 pRet
= reinterpret_cast<ScAutoFormatObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
448 void ScAutoFormatObj::Notify( SfxBroadcaster
& /* rBC */, const SfxHint
& /* rHint */ )
455 ScAutoFormatFieldObj
* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
457 if ( IsInserted() && nIndex
< SC_AF_FIELD_COUNT
)
458 return new ScAutoFormatFieldObj( nFormatIndex
, nIndex
);
463 // container::XEnumerationAccess
465 uno::Reference
<container::XEnumeration
> SAL_CALL
ScAutoFormatObj::createEnumeration()
466 throw(uno::RuntimeException
, std::exception
)
468 SolarMutexGuard aGuard
;
469 return new ScIndexEnumeration(this, OUString("com.sun.star.sheet.TableAutoFormatEnumeration"));
472 // container::XIndexAccess
474 sal_Int32 SAL_CALL
ScAutoFormatObj::getCount() throw(uno::RuntimeException
, std::exception
)
476 SolarMutexGuard aGuard
;
478 return SC_AF_FIELD_COUNT
; // immer 16 Elemente
483 uno::Any SAL_CALL
ScAutoFormatObj::getByIndex( sal_Int32 nIndex
)
484 throw(lang::IndexOutOfBoundsException
,
485 lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
487 SolarMutexGuard aGuard
;
489 if ( nIndex
< 0 || nIndex
>= getCount() )
490 throw lang::IndexOutOfBoundsException();
493 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(GetObjectByIndex_Impl((sal_uInt16
)nIndex
)));
497 uno::Type SAL_CALL
ScAutoFormatObj::getElementType() throw(uno::RuntimeException
, std::exception
)
499 SolarMutexGuard aGuard
;
500 return cppu::UnoType
<beans::XPropertySet
>::get(); // muss zu getByIndex passen
503 sal_Bool SAL_CALL
ScAutoFormatObj::hasElements() throw(uno::RuntimeException
, std::exception
)
505 SolarMutexGuard aGuard
;
506 return ( getCount() != 0 );
511 OUString SAL_CALL
ScAutoFormatObj::getName() throw(uno::RuntimeException
, std::exception
)
513 SolarMutexGuard aGuard
;
514 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
515 if (IsInserted() && nFormatIndex
< pFormats
->size())
516 return pFormats
->findByIndex(nFormatIndex
)->GetName();
521 void SAL_CALL
ScAutoFormatObj::setName( const OUString
& aNewName
)
522 throw (uno::RuntimeException
, std::exception
)
524 SolarMutexGuard aGuard
;
525 OUString
aNewString(aNewName
);
526 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
529 if (IsInserted() && nFormatIndex
< pFormats
->size() &&
530 !lcl_FindAutoFormatIndex( *pFormats
, aNewName
, nDummy
))
532 ScAutoFormat::iterator it
= pFormats
->begin();
533 std::advance(it
, nFormatIndex
);
534 ScAutoFormatData
* pData
= it
->second
;
535 OSL_ENSURE(pData
,"AutoFormat Daten nicht da");
537 ScAutoFormatData
* pNew
= new ScAutoFormatData(*pData
);
538 pNew
->SetName( aNewString
);
541 if (pFormats
->insert(pNew
))
543 it
= pFormats
->find(pNew
);
544 ScAutoFormat::iterator itBeg
= pFormats
->begin();
545 nFormatIndex
= std::distance(itBeg
, it
);
547 //! Notify fuer andere Objekte
548 pFormats
->SetSaveLater(true);
552 OSL_FAIL("AutoFormat konnte nicht eingefuegt werden");
553 nFormatIndex
= 0; //! alter Index ist ungueltig
558 // not inserted or name exists
559 throw uno::RuntimeException();
563 // beans::XPropertySet
565 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScAutoFormatObj::getPropertySetInfo()
566 throw(uno::RuntimeException
, std::exception
)
568 SolarMutexGuard aGuard
;
569 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
573 void SAL_CALL
ScAutoFormatObj::setPropertyValue(
574 const OUString
& aPropertyName
, const uno::Any
& aValue
)
575 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
576 lang::IllegalArgumentException
, lang::WrappedTargetException
,
577 uno::RuntimeException
, std::exception
)
579 SolarMutexGuard aGuard
;
580 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
581 if (IsInserted() && nFormatIndex
< pFormats
->size())
583 ScAutoFormatData
* pData
= pFormats
->findByIndex(nFormatIndex
);
584 OSL_ENSURE(pData
,"AutoFormat Daten nicht da");
586 OUString
aPropString(aPropertyName
);
588 if (aPropString
.equalsAscii( SC_UNONAME_INCBACK
) && (aValue
>>= bBool
))
589 pData
->SetIncludeBackground( bBool
);
590 else if (aPropString
.equalsAscii( SC_UNONAME_INCBORD
) && (aValue
>>= bBool
))
591 pData
->SetIncludeFrame( bBool
);
592 else if (aPropString
.equalsAscii( SC_UNONAME_INCFONT
) && (aValue
>>= bBool
))
593 pData
->SetIncludeFont( bBool
);
594 else if (aPropString
.equalsAscii( SC_UNONAME_INCJUST
) && (aValue
>>= bBool
))
595 pData
->SetIncludeJustify( bBool
);
596 else if (aPropString
.equalsAscii( SC_UNONAME_INCNUM
) && (aValue
>>= bBool
))
597 pData
->SetIncludeValueFormat( bBool
);
598 else if (aPropString
.equalsAscii( SC_UNONAME_INCWIDTH
) && (aValue
>>= bBool
))
599 pData
->SetIncludeWidthHeight( bBool
);
603 //! Notify fuer andere Objekte
604 pFormats
->SetSaveLater(true);
608 uno::Any SAL_CALL
ScAutoFormatObj::getPropertyValue( const OUString
& aPropertyName
)
609 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
610 uno::RuntimeException
, std::exception
)
612 SolarMutexGuard aGuard
;
615 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
616 if (IsInserted() && nFormatIndex
< pFormats
->size())
618 ScAutoFormatData
* pData
= pFormats
->findByIndex(nFormatIndex
);
619 OSL_ENSURE(pData
,"AutoFormat Daten nicht da");
624 if (aPropertyName
.equalsAscii( SC_UNONAME_INCBACK
))
625 bValue
= pData
->GetIncludeBackground();
626 else if (aPropertyName
.equalsAscii( SC_UNONAME_INCBORD
))
627 bValue
= pData
->GetIncludeFrame();
628 else if (aPropertyName
.equalsAscii( SC_UNONAME_INCFONT
))
629 bValue
= pData
->GetIncludeFont();
630 else if (aPropertyName
.equalsAscii( SC_UNONAME_INCJUST
))
631 bValue
= pData
->GetIncludeJustify();
632 else if (aPropertyName
.equalsAscii( SC_UNONAME_INCNUM
))
633 bValue
= pData
->GetIncludeValueFormat();
634 else if (aPropertyName
.equalsAscii( SC_UNONAME_INCWIDTH
))
635 bValue
= pData
->GetIncludeWidthHeight();
637 bError
= true; // unbekannte Property
646 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj
)
648 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat
, sal_uInt16 nField
) :
649 aPropSet( lcl_GetAutoFieldMap() ),
650 nFormatIndex( nFormat
),
651 nFieldIndex( nField
)
656 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
660 void ScAutoFormatFieldObj::Notify( SfxBroadcaster
& /* rBC */, const SfxHint
& /* rHint */ )
665 // beans::XPropertySet
667 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScAutoFormatFieldObj::getPropertySetInfo()
668 throw(uno::RuntimeException
, std::exception
)
670 SolarMutexGuard aGuard
;
671 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
675 void SAL_CALL
ScAutoFormatFieldObj::setPropertyValue(
676 const OUString
& aPropertyName
, const uno::Any
& aValue
)
677 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
678 lang::IllegalArgumentException
, lang::WrappedTargetException
,
679 uno::RuntimeException
, std::exception
)
681 SolarMutexGuard aGuard
;
682 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
683 const SfxItemPropertySimpleEntry
* pEntry
=
684 aPropSet
.getPropertyMap().getByName( aPropertyName
);
686 if ( pEntry
&& pEntry
->nWID
&& nFormatIndex
< pFormats
->size() )
688 ScAutoFormatData
* pData
= pFormats
->findByIndex(nFormatIndex
);
690 if ( IsScItemWid( pEntry
->nWID
) )
692 if( const SfxPoolItem
* pItem
= pData
->GetItem( nFieldIndex
, pEntry
->nWID
) )
696 switch( pEntry
->nWID
)
700 table::CellOrientation eOrient
;
701 if( aValue
>>= eOrient
)
705 case table::CellOrientation_STANDARD
:
706 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, false ) );
708 case table::CellOrientation_TOPBOTTOM
:
709 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, false ) );
710 pData
->PutItem( nFieldIndex
, SfxInt32Item( ATTR_ROTATE_VALUE
, 27000 ) );
712 case table::CellOrientation_BOTTOMTOP
:
713 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, false ) );
714 pData
->PutItem( nFieldIndex
, SfxInt32Item( ATTR_ROTATE_VALUE
, 9000 ) );
716 case table::CellOrientation_STACKED
:
717 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, true ) );
721 // added to avoid warnings
729 SfxPoolItem
* pNewItem
= pItem
->Clone();
730 bDone
= pNewItem
->PutValue( aValue
, pEntry
->nMemberId
);
732 pData
->PutItem( nFieldIndex
, *pNewItem
);
737 //! Notify fuer andere Objekte?
738 pFormats
->SetSaveLater(true);
743 switch (pEntry
->nWID
)
745 case SC_WID_UNO_TBLBORD
:
747 table::TableBorder aBorder
;
748 if ( aValue
>>= aBorder
) // empty = nothing to do
750 SvxBoxItem
aOuter(ATTR_BORDER
);
751 SvxBoxInfoItem
aInner(ATTR_BORDER_INNER
);
752 ScHelperFunctions::FillBoxItems( aOuter
, aInner
, aBorder
);
753 pData
->PutItem( nFieldIndex
, aOuter
);
755 //! Notify for other objects?
756 pFormats
->SetSaveLater(true);
760 case SC_WID_UNO_TBLBORD2
:
762 table::TableBorder2 aBorder2
;
763 if ( aValue
>>= aBorder2
) // empty = nothing to do
765 SvxBoxItem
aOuter(ATTR_BORDER
);
766 SvxBoxInfoItem
aInner(ATTR_BORDER_INNER
);
767 ScHelperFunctions::FillBoxItems( aOuter
, aInner
, aBorder2
);
768 pData
->PutItem( nFieldIndex
, aOuter
);
770 //! Notify for other objects?
771 pFormats
->SetSaveLater(true);
780 uno::Any SAL_CALL
ScAutoFormatFieldObj::getPropertyValue( const OUString
& aPropertyName
)
781 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
782 uno::RuntimeException
, std::exception
)
784 SolarMutexGuard aGuard
;
787 ScAutoFormat
* pFormats
= ScGlobal::GetOrCreateAutoFormat();
788 const SfxItemPropertySimpleEntry
* pEntry
=
789 aPropSet
.getPropertyMap().getByName( aPropertyName
);
791 if ( pEntry
&& pEntry
->nWID
&& nFormatIndex
< pFormats
->size() )
793 const ScAutoFormatData
* pData
= pFormats
->findByIndex(nFormatIndex
);
795 if ( IsScItemWid( pEntry
->nWID
) )
797 if( const SfxPoolItem
* pItem
= pData
->GetItem( nFieldIndex
, pEntry
->nWID
) )
799 switch( pEntry
->nWID
)
803 const SfxInt32Item
* pRotItem
= (const SfxInt32Item
*)pData
->GetItem( nFieldIndex
, ATTR_ROTATE_VALUE
);
804 sal_Int32 nRot
= pRotItem
? pRotItem
->GetValue() : 0;
805 bool bStacked
= ((const SfxBoolItem
*)pItem
)->GetValue();
806 SvxOrientationItem( nRot
, bStacked
, 0 ).QueryValue( aVal
);
810 pItem
->QueryValue( aVal
, pEntry
->nMemberId
);
816 switch (pEntry
->nWID
)
818 case SC_WID_UNO_TBLBORD
:
819 case SC_WID_UNO_TBLBORD2
:
821 const SfxPoolItem
* pItem
= pData
->GetItem(nFieldIndex
, ATTR_BORDER
);
824 SvxBoxItem
aOuter(*(static_cast<const SvxBoxItem
*>(pItem
)));
825 SvxBoxInfoItem
aInner(ATTR_BORDER_INNER
);
827 if (pEntry
->nWID
== SC_WID_UNO_TBLBORD2
)
828 ScHelperFunctions::AssignTableBorder2ToAny( aVal
, aOuter
, aInner
);
830 ScHelperFunctions::AssignTableBorderToAny( aVal
, aOuter
, aInner
);
841 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj
)
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */