1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: afmtuno.cxx,v $
10 * $Revision: 1.16.144.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "scitems.hxx"
37 #include <tools/debug.hxx>
38 #include <tools/shl.hxx>
39 #include <svtools/poolitem.hxx>
40 #include <svx/unomid.hxx>
41 #include "unowids.hxx"
43 #include <com/sun/star/table/BorderLine.hpp>
44 #include <com/sun/star/table/CellVertJustify.hpp>
45 #include <com/sun/star/table/ShadowLocation.hpp>
46 #include <com/sun/star/table/TableBorder.hpp>
47 #include <com/sun/star/table/ShadowFormat.hpp>
48 #include <com/sun/star/table/CellRangeAddress.hpp>
49 #include <com/sun/star/table/CellContentType.hpp>
50 #include <com/sun/star/table/TableOrientation.hpp>
51 #include <com/sun/star/table/CellHoriJustify.hpp>
52 #include <com/sun/star/util/SortField.hpp>
53 #include <com/sun/star/util/SortFieldType.hpp>
54 #include <com/sun/star/table/CellOrientation.hpp>
55 #include <com/sun/star/table/CellAddress.hpp>
56 #include <com/sun/star/awt/SimpleFontMetric.hpp>
57 #include <com/sun/star/awt/FontWeight.hpp>
58 #include <com/sun/star/awt/FontSlant.hpp>
59 #include <com/sun/star/awt/CharSet.hpp>
60 #include <com/sun/star/awt/FontDescriptor.hpp>
61 #include <com/sun/star/awt/FontWidth.hpp>
62 #include <com/sun/star/awt/XFont.hpp>
63 #include <com/sun/star/awt/FontType.hpp>
64 #include <com/sun/star/awt/FontUnderline.hpp>
65 #include <com/sun/star/awt/FontStrikeout.hpp>
66 #include <com/sun/star/awt/FontFamily.hpp>
67 #include <com/sun/star/awt/FontPitch.hpp>
69 #include "afmtuno.hxx"
70 #include "miscuno.hxx"
71 #include "autoform.hxx"
72 #include "unoguard.hxx"
74 #include "unonames.hxx"
75 #include "cellsuno.hxx"
77 using namespace ::com::sun::star
;
79 //------------------------------------------------------------------------
81 // ein AutoFormat hat immer 16 Eintraege
82 #define SC_AF_FIELD_COUNT 16
84 //------------------------------------------------------------------------
86 // AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs
88 const SfxItemPropertyMapEntry
* lcl_GetAutoFormatMap()
90 static SfxItemPropertyMapEntry aAutoFormatMap_Impl
[] =
92 {MAP_CHAR_LEN(SC_UNONAME_INCBACK
), 0, &::getBooleanCppuType(), 0, 0 },
93 {MAP_CHAR_LEN(SC_UNONAME_INCBORD
), 0, &::getBooleanCppuType(), 0, 0 },
94 {MAP_CHAR_LEN(SC_UNONAME_INCFONT
), 0, &::getBooleanCppuType(), 0, 0 },
95 {MAP_CHAR_LEN(SC_UNONAME_INCJUST
), 0, &::getBooleanCppuType(), 0, 0 },
96 {MAP_CHAR_LEN(SC_UNONAME_INCNUM
), 0, &::getBooleanCppuType(), 0, 0 },
97 {MAP_CHAR_LEN(SC_UNONAME_INCWIDTH
), 0, &::getBooleanCppuType(), 0, 0 },
100 return aAutoFormatMap_Impl
;
103 //! Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly)
104 //! table::TableBorder ??!?
106 const SfxItemPropertyMapEntry
* lcl_GetAutoFieldMap()
108 static SfxItemPropertyMapEntry aAutoFieldMap_Impl
[] =
110 {MAP_CHAR_LEN(SC_UNONAME_CELLBACK
), ATTR_BACKGROUND
, &::getCppuType((const sal_Int32
*)0), 0, MID_BACK_COLOR
},
111 {MAP_CHAR_LEN(SC_UNONAME_CCOLOR
), ATTR_FONT_COLOR
, &::getCppuType((const sal_Int32
*)0), 0, 0 },
112 {MAP_CHAR_LEN(SC_UNONAME_COUTL
), ATTR_FONT_CONTOUR
, &::getBooleanCppuType(), 0, 0 },
113 {MAP_CHAR_LEN(SC_UNONAME_CCROSS
), ATTR_FONT_CROSSEDOUT
, &::getBooleanCppuType(), 0, MID_CROSSED_OUT
},
114 {MAP_CHAR_LEN(SC_UNONAME_CFONT
), ATTR_FONT
, &::getCppuType((const sal_Int16
*)0), 0, MID_FONT_FAMILY
},
115 {MAP_CHAR_LEN(SC_UNONAME_CFCHARS
), ATTR_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_CHAR_SET
},
116 {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS
), ATTR_CJK_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_CHAR_SET
},
117 {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS
), ATTR_CTL_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_CHAR_SET
},
118 {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL
), ATTR_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_FAMILY
},
119 {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL
), ATTR_CJK_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_FAMILY
},
120 {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL
), ATTR_CTL_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_FAMILY
},
121 {MAP_CHAR_LEN(SC_UNONAME_CFNAME
), ATTR_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_FAMILY_NAME
},
122 {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME
), ATTR_CJK_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_FAMILY_NAME
},
123 {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME
), ATTR_CTL_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_FAMILY_NAME
},
124 {MAP_CHAR_LEN(SC_UNONAME_CFPITCH
), ATTR_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_PITCH
},
125 {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH
), ATTR_CJK_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_PITCH
},
126 {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH
), ATTR_CTL_FONT
, &::getCppuType((sal_Int16
*)0), 0, MID_FONT_PITCH
},
127 {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE
), ATTR_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_STYLE_NAME
},
128 {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE
), ATTR_CJK_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_STYLE_NAME
},
129 {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE
), ATTR_CTL_FONT
, &::getCppuType((rtl::OUString
*)0), 0, MID_FONT_STYLE_NAME
},
130 {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT
), ATTR_FONT_HEIGHT
, &::getCppuType((float*)0), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
131 {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT
), ATTR_CJK_FONT_HEIGHT
, &::getCppuType((float*)0), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
132 {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT
), ATTR_CTL_FONT_HEIGHT
, &::getCppuType((float*)0), 0, MID_FONTHEIGHT
| CONVERT_TWIPS
},
133 {MAP_CHAR_LEN(SC_UNONAME_COVER
), ATTR_FONT_OVERLINE
, &::getCppuType((const sal_Int16
*)0), 0, MID_TL_STYLE
},
134 {MAP_CHAR_LEN(SC_UNONAME_CPOST
), ATTR_FONT_POSTURE
, &::getCppuType((awt::FontSlant
*)0), 0, MID_POSTURE
},
135 {MAP_CHAR_LEN(SC_UNO_CJK_CPOST
), ATTR_CJK_FONT_POSTURE
, &::getCppuType((awt::FontSlant
*)0), 0, MID_POSTURE
},
136 {MAP_CHAR_LEN(SC_UNO_CTL_CPOST
), ATTR_CTL_FONT_POSTURE
, &::getCppuType((awt::FontSlant
*)0), 0, MID_POSTURE
},
137 {MAP_CHAR_LEN(SC_UNONAME_CSHADD
), ATTR_FONT_SHADOWED
, &::getBooleanCppuType(), 0, 0 },
138 {MAP_CHAR_LEN(SC_UNONAME_TBLBORD
), SC_WID_UNO_TBLBORD
, &::getCppuType((table::TableBorder
*)0), 0, 0 | CONVERT_TWIPS
},
139 {MAP_CHAR_LEN(SC_UNONAME_CUNDER
), ATTR_FONT_UNDERLINE
, &::getCppuType((const sal_Int16
*)0), 0, MID_TL_STYLE
},
140 {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT
), ATTR_FONT_WEIGHT
, &::getCppuType((float*)0), 0, MID_WEIGHT
},
141 {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT
), ATTR_CJK_FONT_WEIGHT
, &::getCppuType((float*)0), 0, MID_WEIGHT
},
142 {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT
), ATTR_CTL_FONT_WEIGHT
, &::getCppuType((float*)0), 0, MID_WEIGHT
},
143 {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS
), ATTR_HOR_JUSTIFY
, &::getCppuType((const table::CellHoriJustify
*)0), 0, 0 },
144 {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN
), ATTR_BACKGROUND
, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT
},
145 {MAP_CHAR_LEN(SC_UNONAME_WRAP
), ATTR_LINEBREAK
, &::getBooleanCppuType(), 0, 0 },
146 {MAP_CHAR_LEN(SC_UNONAME_CELLORI
), ATTR_STACKED
, &::getCppuType((const table::CellOrientation
*)0), 0, 0 },
147 {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN
), ATTR_MARGIN
, &::getCppuType((const sal_Int32
*)0), 0, MID_MARGIN_LO_MARGIN
| CONVERT_TWIPS
},
148 {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN
), ATTR_MARGIN
, &::getCppuType((const sal_Int32
*)0), 0, MID_MARGIN_L_MARGIN
| CONVERT_TWIPS
},
149 {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN
), ATTR_MARGIN
, &::getCppuType((const sal_Int32
*)0), 0, MID_MARGIN_R_MARGIN
| CONVERT_TWIPS
},
150 {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN
), ATTR_MARGIN
, &::getCppuType((const sal_Int32
*)0), 0, MID_MARGIN_UP_MARGIN
| CONVERT_TWIPS
},
151 {MAP_CHAR_LEN(SC_UNONAME_ROTANG
), ATTR_ROTATE_VALUE
, &::getCppuType((const sal_Int32
*)0), 0, 0 },
152 {MAP_CHAR_LEN(SC_UNONAME_ROTREF
), ATTR_ROTATE_MODE
, &::getCppuType((const table::CellVertJustify
*)0), 0, 0 },
153 {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS
), ATTR_VER_JUSTIFY
, &::getCppuType((const table::CellVertJustify
*)0), 0, 0 },
156 return aAutoFieldMap_Impl
;
159 //------------------------------------------------------------------------
161 #define SCAUTOFORMATSOBJ_SERVICE "com.sun.star.sheet.TableAutoFormats"
163 SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj
, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" )
164 SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj
, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" )
165 SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj
, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE
)
167 //------------------------------------------------------------------------
169 sal_Bool
lcl_FindAutoFormatIndex( const ScAutoFormat
& rFormats
, const String
& rName
, sal_uInt16
& rOutIndex
)
172 sal_uInt16 nCount
= rFormats
.GetCount();
173 for( sal_uInt16 nPos
=0; nPos
<nCount
; nPos
++ )
175 ScAutoFormatData
* pEntry
= rFormats
[nPos
];
176 pEntry
->GetName( aEntryName
);
177 if ( aEntryName
== rName
)
183 return sal_False
; // is nich
186 //------------------------------------------------------------------------
188 ScAutoFormatsObj::ScAutoFormatsObj()
190 //! Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten
191 //! bekannt sein, damit Aenderungen gebroadcasted werden koennen
194 ScAutoFormatsObj::~ScAutoFormatsObj()
198 // stuff for exService_...
200 uno::Reference
<uno::XInterface
> SAL_CALL
ScAutoFormatsObj_CreateInstance(
201 const uno::Reference
<lang::XMultiServiceFactory
>& )
205 static uno::Reference
< uno::XInterface
> xInst((::cppu::OWeakObject
*) new ScAutoFormatsObj
);
209 rtl::OUString
ScAutoFormatsObj::getImplementationName_Static()
211 return rtl::OUString::createFromAscii( "stardiv.StarCalc.ScAutoFormatsObj" );
214 uno::Sequence
<rtl::OUString
> ScAutoFormatsObj::getSupportedServiceNames_Static()
216 uno::Sequence
<rtl::OUString
> aRet(1);
217 rtl::OUString
* pArray
= aRet
.getArray();
218 pArray
[0] = rtl::OUString::createFromAscii( SCAUTOFORMATSOBJ_SERVICE
);
224 ScAutoFormatObj
* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
226 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
227 if (pFormats
&& nIndex
< pFormats
->GetCount())
228 return new ScAutoFormatObj(nIndex
);
230 return NULL
; // falscher Index
233 ScAutoFormatObj
* ScAutoFormatsObj::GetObjectByName_Impl(const rtl::OUString
& aName
)
235 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
238 String
aString(aName
);
240 if (lcl_FindAutoFormatIndex( *pFormats
, aString
, nIndex
))
241 return GetObjectByIndex_Impl(nIndex
);
246 // container::XNameContainer
248 void SAL_CALL
ScAutoFormatsObj::insertByName( const rtl::OUString
& aName
, const uno::Any
& aElement
)
249 throw(lang::IllegalArgumentException
, container::ElementExistException
,
250 lang::WrappedTargetException
, uno::RuntimeException
)
253 sal_Bool bDone
= sal_False
;
254 // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein...
255 uno::Reference
< uno::XInterface
> xInterface(aElement
, uno::UNO_QUERY
);
256 if ( xInterface
.is() )
258 ScAutoFormatObj
* pFormatObj
= ScAutoFormatObj::getImplementation( xInterface
);
259 if ( pFormatObj
&& !pFormatObj
->IsInserted() ) // noch nicht eingefuegt?
261 String
aNameStr(aName
);
262 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
265 if (pFormats
&& !lcl_FindAutoFormatIndex( *pFormats
, aNameStr
, nDummy
))
267 ScAutoFormatData
* pNew
= new ScAutoFormatData();
268 pNew
->SetName( aNameStr
);
270 if (pFormats
->Insert( pNew
))
272 //! Notify fuer andere Objekte
273 pFormats
->Save(); // sofort speichern
275 sal_uInt16 nNewIndex
;
276 if (lcl_FindAutoFormatIndex( *pFormats
, aNameStr
, nNewIndex
))
278 pFormatObj
->InitFormat( nNewIndex
); // kann jetzt benutzt werden
285 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
286 throw uno::RuntimeException();
291 throw container::ElementExistException();
298 // other errors are handled above
299 throw lang::IllegalArgumentException();
303 void SAL_CALL
ScAutoFormatsObj::replaceByName( const rtl::OUString
& aName
, const uno::Any
& aElement
)
304 throw(lang::IllegalArgumentException
, container::NoSuchElementException
,
305 lang::WrappedTargetException
, uno::RuntimeException
)
309 removeByName( aName
);
310 insertByName( aName
, aElement
);
313 void SAL_CALL
ScAutoFormatsObj::removeByName( const rtl::OUString
& aName
)
314 throw(container::NoSuchElementException
,
315 lang::WrappedTargetException
, uno::RuntimeException
)
318 String
aNameStr(aName
);
319 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
322 if (pFormats
&& lcl_FindAutoFormatIndex( *pFormats
, aNameStr
, nIndex
))
324 pFormats
->AtFree( nIndex
);
326 //! Notify fuer andere Objekte
327 pFormats
->Save(); // sofort speichern
331 throw container::NoSuchElementException();
335 // container::XEnumerationAccess
337 uno::Reference
<container::XEnumeration
> SAL_CALL
ScAutoFormatsObj::createEnumeration()
338 throw(uno::RuntimeException
)
341 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
344 // container::XIndexAccess
346 sal_Int32 SAL_CALL
ScAutoFormatsObj::getCount() throw(uno::RuntimeException
)
349 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
351 return pFormats
->GetCount();
356 uno::Any SAL_CALL
ScAutoFormatsObj::getByIndex( sal_Int32 nIndex
)
357 throw(lang::IndexOutOfBoundsException
,
358 lang::WrappedTargetException
, uno::RuntimeException
)
361 uno::Reference
< container::XNamed
> xFormat(GetObjectByIndex_Impl((sal_uInt16
)nIndex
));
363 throw lang::IndexOutOfBoundsException();
364 return uno::makeAny(xFormat
);
367 uno::Type SAL_CALL
ScAutoFormatsObj::getElementType() throw(uno::RuntimeException
)
370 return ::getCppuType((const uno::Reference
< container::XNamed
>*)0); // muss zu getByIndex passen
373 sal_Bool SAL_CALL
ScAutoFormatsObj::hasElements() throw(uno::RuntimeException
)
376 return ( getCount() != 0 );
379 // container::XNameAccess
381 uno::Any SAL_CALL
ScAutoFormatsObj::getByName( const rtl::OUString
& aName
)
382 throw(container::NoSuchElementException
,
383 lang::WrappedTargetException
, uno::RuntimeException
)
386 uno::Reference
< container::XNamed
> xFormat(GetObjectByName_Impl(aName
));
388 throw container::NoSuchElementException();
389 return uno::makeAny(xFormat
);
392 uno::Sequence
<rtl::OUString
> SAL_CALL
ScAutoFormatsObj::getElementNames()
393 throw(uno::RuntimeException
)
396 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
400 sal_uInt16 nCount
= pFormats
->GetCount();
401 uno::Sequence
<rtl::OUString
> aSeq(nCount
);
402 rtl::OUString
* pAry
= aSeq
.getArray();
403 for (sal_uInt16 i
=0; i
<nCount
; i
++)
405 (*pFormats
)[i
]->GetName(aName
);
410 return uno::Sequence
<rtl::OUString
>(0);
413 sal_Bool SAL_CALL
ScAutoFormatsObj::hasByName( const rtl::OUString
& aName
)
414 throw(uno::RuntimeException
)
417 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
420 String
aString(aName
);
422 return lcl_FindAutoFormatIndex( *pFormats
, aString
, nDummy
);
427 //------------------------------------------------------------------------
429 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex
) :
430 aPropSet( lcl_GetAutoFormatMap() ),
431 nFormatIndex( nIndex
)
436 ScAutoFormatObj::~ScAutoFormatObj()
438 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
439 // gespeichert, damit sie z.B. im Writer sichtbar sind
443 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
444 if ( pFormats
&& pFormats
->IsSaveLater() )
447 // Save() setzt SaveLater Flag zurueck
451 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex
)
453 DBG_ASSERT( nFormatIndex
== SC_AFMTOBJ_INVALID
, "ScAutoFormatObj::InitFormat mehrfach" );
454 nFormatIndex
= nNewIndex
;
460 sal_Int64 SAL_CALL
ScAutoFormatObj::getSomething(
461 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
)
463 if ( rId
.getLength() == 16 &&
464 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
465 rId
.getConstArray(), 16 ) )
467 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
473 const uno::Sequence
<sal_Int8
>& ScAutoFormatObj::getUnoTunnelId()
475 static uno::Sequence
<sal_Int8
> * pSeq
= 0;
478 osl::Guard
< osl::Mutex
> aGuard( osl::Mutex::getGlobalMutex() );
481 static uno::Sequence
< sal_Int8
> aSeq( 16 );
482 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
490 ScAutoFormatObj
* ScAutoFormatObj::getImplementation(
491 const uno::Reference
<uno::XInterface
> xObj
)
493 ScAutoFormatObj
* pRet
= NULL
;
494 uno::Reference
<lang::XUnoTunnel
> xUT( xObj
, uno::UNO_QUERY
);
496 pRet
= reinterpret_cast<ScAutoFormatObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
500 void ScAutoFormatObj::Notify( SfxBroadcaster
& /* rBC */, const SfxHint
& /* rHint */ )
507 ScAutoFormatFieldObj
* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex
)
509 if ( IsInserted() && nIndex
< SC_AF_FIELD_COUNT
)
510 return new ScAutoFormatFieldObj( nFormatIndex
, nIndex
);
515 // container::XEnumerationAccess
517 uno::Reference
<container::XEnumeration
> SAL_CALL
ScAutoFormatObj::createEnumeration()
518 throw(uno::RuntimeException
)
521 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
524 // container::XIndexAccess
526 sal_Int32 SAL_CALL
ScAutoFormatObj::getCount() throw(uno::RuntimeException
)
530 return SC_AF_FIELD_COUNT
; // immer 16 Elemente
535 uno::Any SAL_CALL
ScAutoFormatObj::getByIndex( sal_Int32 nIndex
)
536 throw(lang::IndexOutOfBoundsException
,
537 lang::WrappedTargetException
, uno::RuntimeException
)
541 if ( nIndex
< 0 || nIndex
>= getCount() )
542 throw lang::IndexOutOfBoundsException();
545 return uno::makeAny(uno::Reference
< beans::XPropertySet
>(GetObjectByIndex_Impl((sal_uInt16
)nIndex
)));
549 uno::Type SAL_CALL
ScAutoFormatObj::getElementType() throw(uno::RuntimeException
)
552 return ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0); // muss zu getByIndex passen
555 sal_Bool SAL_CALL
ScAutoFormatObj::hasElements() throw(uno::RuntimeException
)
558 return ( getCount() != 0 );
563 rtl::OUString SAL_CALL
ScAutoFormatObj::getName() throw(uno::RuntimeException
)
566 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
567 if (pFormats
&& IsInserted() && nFormatIndex
< pFormats
->GetCount())
570 (*pFormats
)[nFormatIndex
]->GetName(aName
);
573 return rtl::OUString();
576 void SAL_CALL
ScAutoFormatObj::setName( const rtl::OUString
& aNewName
)
577 throw(uno::RuntimeException
)
580 String
aNewString(aNewName
);
581 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
584 if (pFormats
&& IsInserted() && nFormatIndex
< pFormats
->GetCount() &&
585 !lcl_FindAutoFormatIndex( *pFormats
, aNewString
, nDummy
))
587 ScAutoFormatData
* pData
= (*pFormats
)[nFormatIndex
];
588 DBG_ASSERT(pData
,"AutoFormat Daten nicht da");
590 ScAutoFormatData
* pNew
= new ScAutoFormatData(*pData
);
591 pNew
->SetName( aNewString
);
593 pFormats
->AtFree( nFormatIndex
);
594 if (pFormats
->Insert( pNew
))
596 nFormatIndex
= pFormats
->IndexOf( pNew
); // ist evtl. anders einsortiert...
598 //! Notify fuer andere Objekte
599 pFormats
->SetSaveLater(sal_True
);
604 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
605 nFormatIndex
= 0; //! alter Index ist ungueltig
610 // not inserted or name exists
611 throw uno::RuntimeException();
615 // beans::XPropertySet
617 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScAutoFormatObj::getPropertySetInfo()
618 throw(uno::RuntimeException
)
621 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
625 void SAL_CALL
ScAutoFormatObj::setPropertyValue(
626 const rtl::OUString
& aPropertyName
, const uno::Any
& aValue
)
627 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
628 lang::IllegalArgumentException
, lang::WrappedTargetException
,
629 uno::RuntimeException
)
632 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
633 if (pFormats
&& IsInserted() && nFormatIndex
< pFormats
->GetCount())
635 ScAutoFormatData
* pData
= (*pFormats
)[nFormatIndex
];
636 DBG_ASSERT(pData
,"AutoFormat Daten nicht da");
638 String
aPropString(aPropertyName
);
639 sal_Bool bBool
= sal_Bool();
640 if (aPropString
.EqualsAscii( SC_UNONAME_INCBACK
) && (aValue
>>= bBool
))
641 pData
->SetIncludeBackground( bBool
);
642 else if (aPropString
.EqualsAscii( SC_UNONAME_INCBORD
) && (aValue
>>= bBool
))
643 pData
->SetIncludeFrame( bBool
);
644 else if (aPropString
.EqualsAscii( SC_UNONAME_INCFONT
) && (aValue
>>= bBool
))
645 pData
->SetIncludeFont( bBool
);
646 else if (aPropString
.EqualsAscii( SC_UNONAME_INCJUST
) && (aValue
>>= bBool
))
647 pData
->SetIncludeJustify( bBool
);
648 else if (aPropString
.EqualsAscii( SC_UNONAME_INCNUM
) && (aValue
>>= bBool
))
649 pData
->SetIncludeValueFormat( bBool
);
650 else if (aPropString
.EqualsAscii( SC_UNONAME_INCWIDTH
) && (aValue
>>= bBool
))
651 pData
->SetIncludeWidthHeight( bBool
);
655 //! Notify fuer andere Objekte
656 pFormats
->SetSaveLater(sal_True
);
660 uno::Any SAL_CALL
ScAutoFormatObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
661 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
662 uno::RuntimeException
)
667 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
668 if (pFormats
&& IsInserted() && nFormatIndex
< pFormats
->GetCount())
670 ScAutoFormatData
* pData
= (*pFormats
)[nFormatIndex
];
671 DBG_ASSERT(pData
,"AutoFormat Daten nicht da");
674 sal_Bool bError
= sal_False
;
676 String
aPropString(aPropertyName
);
677 if (aPropString
.EqualsAscii( SC_UNONAME_INCBACK
))
678 bValue
= pData
->GetIncludeBackground();
679 else if (aPropString
.EqualsAscii( SC_UNONAME_INCBORD
))
680 bValue
= pData
->GetIncludeFrame();
681 else if (aPropString
.EqualsAscii( SC_UNONAME_INCFONT
))
682 bValue
= pData
->GetIncludeFont();
683 else if (aPropString
.EqualsAscii( SC_UNONAME_INCJUST
))
684 bValue
= pData
->GetIncludeJustify();
685 else if (aPropString
.EqualsAscii( SC_UNONAME_INCNUM
))
686 bValue
= pData
->GetIncludeValueFormat();
687 else if (aPropString
.EqualsAscii( SC_UNONAME_INCWIDTH
))
688 bValue
= pData
->GetIncludeWidthHeight();
690 bError
= sal_True
; // unbekannte Property
699 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj
)
701 //------------------------------------------------------------------------
703 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat
, sal_uInt16 nField
) :
704 aPropSet( lcl_GetAutoFieldMap() ),
705 nFormatIndex( nFormat
),
706 nFieldIndex( nField
)
711 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
715 void ScAutoFormatFieldObj::Notify( SfxBroadcaster
& /* rBC */, const SfxHint
& /* rHint */ )
720 // beans::XPropertySet
722 uno::Reference
<beans::XPropertySetInfo
> SAL_CALL
ScAutoFormatFieldObj::getPropertySetInfo()
723 throw(uno::RuntimeException
)
726 static uno::Reference
< beans::XPropertySetInfo
> aRef(new SfxItemPropertySetInfo( aPropSet
.getPropertyMap() ));
730 void SAL_CALL
ScAutoFormatFieldObj::setPropertyValue(
731 const rtl::OUString
& aPropertyName
, const uno::Any
& aValue
)
732 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
,
733 lang::IllegalArgumentException
, lang::WrappedTargetException
,
734 uno::RuntimeException
)
737 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
738 const SfxItemPropertySimpleEntry
* pEntry
=
739 aPropSet
.getPropertyMap()->getByName( aPropertyName
);
741 if ( pEntry
&& pEntry
->nWID
&& pFormats
&& nFormatIndex
< pFormats
->GetCount() )
743 ScAutoFormatData
* pData
= (*pFormats
)[nFormatIndex
];
745 if ( IsScItemWid( pEntry
->nWID
) )
747 if( const SfxPoolItem
* pItem
= pData
->GetItem( nFieldIndex
, pEntry
->nWID
) )
749 sal_Bool bDone
= sal_False
;
751 switch( pEntry
->nWID
)
755 table::CellOrientation eOrient
;
756 if( aValue
>>= eOrient
)
760 case table::CellOrientation_STANDARD
:
761 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, FALSE
) );
763 case table::CellOrientation_TOPBOTTOM
:
764 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, FALSE
) );
765 pData
->PutItem( nFieldIndex
, SfxInt32Item( ATTR_ROTATE_VALUE
, 27000 ) );
767 case table::CellOrientation_BOTTOMTOP
:
768 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, FALSE
) );
769 pData
->PutItem( nFieldIndex
, SfxInt32Item( ATTR_ROTATE_VALUE
, 9000 ) );
771 case table::CellOrientation_STACKED
:
772 pData
->PutItem( nFieldIndex
, SfxBoolItem( ATTR_STACKED
, TRUE
) );
776 // added to avoid warnings
784 SfxPoolItem
* pNewItem
= pItem
->Clone();
785 bDone
= pNewItem
->PutValue( aValue
, pEntry
->nMemberId
);
787 pData
->PutItem( nFieldIndex
, *pNewItem
);
792 //! Notify fuer andere Objekte?
793 pFormats
->SetSaveLater(sal_True
);
798 switch (pEntry
->nWID
)
800 case SC_WID_UNO_TBLBORD
:
802 table::TableBorder aBorder
;
803 if ( aValue
>>= aBorder
) // empty = nothing to do
805 SvxBoxItem
aOuter(ATTR_BORDER
);
806 SvxBoxInfoItem
aInner(ATTR_BORDER_INNER
);
807 ScHelperFunctions::FillBoxItems( aOuter
, aInner
, aBorder
);
808 pData
->PutItem( nFieldIndex
, aOuter
);
810 //! Notify fuer andere Objekte?
811 pFormats
->SetSaveLater(sal_True
);
820 uno::Any SAL_CALL
ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString
& aPropertyName
)
821 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
,
822 uno::RuntimeException
)
827 ScAutoFormat
* pFormats
= ScGlobal::GetAutoFormat();
828 const SfxItemPropertySimpleEntry
* pEntry
=
829 aPropSet
.getPropertyMap()->getByName( aPropertyName
);
831 if ( pEntry
&& pEntry
->nWID
&& pFormats
&& nFormatIndex
< pFormats
->GetCount() )
833 const ScAutoFormatData
* pData
= (*pFormats
)[nFormatIndex
];
835 if ( IsScItemWid( pEntry
->nWID
) )
837 if( const SfxPoolItem
* pItem
= pData
->GetItem( nFieldIndex
, pEntry
->nWID
) )
839 switch( pEntry
->nWID
)
843 const SfxInt32Item
* pRotItem
= (const SfxInt32Item
*)pData
->GetItem( nFieldIndex
, ATTR_ROTATE_VALUE
);
844 sal_Int32 nRot
= pRotItem
? pRotItem
->GetValue() : 0;
845 BOOL bStacked
= ((const SfxBoolItem
*)pItem
)->GetValue();
846 SvxOrientationItem( nRot
, bStacked
, 0 ).QueryValue( aVal
);
850 pItem
->QueryValue( aVal
, pEntry
->nMemberId
);
856 switch (pEntry
->nWID
)
858 case SC_WID_UNO_TBLBORD
:
860 const SfxPoolItem
* pItem
= pData
->GetItem(nFieldIndex
, ATTR_BORDER
);
863 SvxBoxItem
aOuter(*(static_cast<const SvxBoxItem
*>(pItem
)));
864 SvxBoxInfoItem
aInner(ATTR_BORDER_INNER
);
866 table::TableBorder aBorder
;
867 ScHelperFunctions::FillTableBorder( aBorder
, aOuter
, aInner
);
879 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj
)
881 //------------------------------------------------------------------------