merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / unoobj / afmtuno.cxx
blob2fcdc276625bbeb04f299f2dd3848a8e785fb871
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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"
42 #include <rtl/uuid.h>
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"
73 #include "scdll.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 },
98 {0,0,0,0,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 },
154 {0,0,0,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 )
171 String aEntryName;
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 )
179 rOutIndex = nPos;
180 return sal_True;
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>& )
203 ScUnoGuard aGuard;
204 ScDLL::Init();
205 static uno::Reference< uno::XInterface > xInst((::cppu::OWeakObject*) new ScAutoFormatsObj);
206 return xInst;
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 );
219 return aRet;
222 // XTableAutoFormats
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();
236 if (pFormats)
238 String aString(aName);
239 sal_uInt16 nIndex;
240 if (lcl_FindAutoFormatIndex( *pFormats, aString, nIndex ))
241 return GetObjectByIndex_Impl(nIndex);
243 return NULL;
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)
252 ScUnoGuard aGuard;
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();
264 sal_uInt16 nDummy;
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
279 bDone = sal_True;
282 else
284 delete pNew;
285 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
286 throw uno::RuntimeException();
289 else
291 throw container::ElementExistException();
296 if (!bDone)
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)
307 ScUnoGuard aGuard;
308 //! zusammenfassen?
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)
317 ScUnoGuard aGuard;
318 String aNameStr(aName);
319 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
321 sal_uInt16 nIndex;
322 if (pFormats && lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex ))
324 pFormats->AtFree( nIndex );
326 //! Notify fuer andere Objekte
327 pFormats->Save(); // sofort speichern
329 else
331 throw container::NoSuchElementException();
335 // container::XEnumerationAccess
337 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
338 throw(uno::RuntimeException)
340 ScUnoGuard aGuard;
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)
348 ScUnoGuard aGuard;
349 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
350 if (pFormats)
351 return pFormats->GetCount();
353 return 0;
356 uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
357 throw(lang::IndexOutOfBoundsException,
358 lang::WrappedTargetException, uno::RuntimeException)
360 ScUnoGuard aGuard;
361 uno::Reference< container::XNamed > xFormat(GetObjectByIndex_Impl((sal_uInt16)nIndex));
362 if (!xFormat.is())
363 throw lang::IndexOutOfBoundsException();
364 return uno::makeAny(xFormat);
367 uno::Type SAL_CALL ScAutoFormatsObj::getElementType() throw(uno::RuntimeException)
369 ScUnoGuard aGuard;
370 return ::getCppuType((const uno::Reference< container::XNamed >*)0); // muss zu getByIndex passen
373 sal_Bool SAL_CALL ScAutoFormatsObj::hasElements() throw(uno::RuntimeException)
375 ScUnoGuard aGuard;
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)
385 ScUnoGuard aGuard;
386 uno::Reference< container::XNamed > xFormat(GetObjectByName_Impl(aName));
387 if (!xFormat.is())
388 throw container::NoSuchElementException();
389 return uno::makeAny(xFormat);
392 uno::Sequence<rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
393 throw(uno::RuntimeException)
395 ScUnoGuard aGuard;
396 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
397 if (pFormats)
399 String aName;
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);
406 pAry[i] = aName;
408 return aSeq;
410 return uno::Sequence<rtl::OUString>(0);
413 sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const rtl::OUString& aName )
414 throw(uno::RuntimeException)
416 ScUnoGuard aGuard;
417 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
418 if (pFormats)
420 String aString(aName);
421 sal_uInt16 nDummy;
422 return lcl_FindAutoFormatIndex( *pFormats, aString, nDummy );
424 return sal_False;
427 //------------------------------------------------------------------------
429 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
430 aPropSet( lcl_GetAutoFormatMap() ),
431 nFormatIndex( nIndex )
433 //! Listening !!!
436 ScAutoFormatObj::~ScAutoFormatObj()
438 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
439 // gespeichert, damit sie z.B. im Writer sichtbar sind
441 if (IsInserted())
443 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
444 if ( pFormats && pFormats->IsSaveLater() )
445 pFormats->Save();
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;
455 //! Listening !!!
458 // XUnoTunnel
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));
469 return 0;
472 // static
473 const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId()
475 static uno::Sequence<sal_Int8> * pSeq = 0;
476 if( !pSeq )
478 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
479 if( !pSeq )
481 static uno::Sequence< sal_Int8 > aSeq( 16 );
482 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
483 pSeq = &aSeq;
486 return *pSeq;
489 // static
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 );
495 if (xUT.is())
496 pRet = reinterpret_cast<ScAutoFormatObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
497 return pRet;
500 void ScAutoFormatObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
502 // spaeter...
505 // XTableAutoFormat
507 ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
509 if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
510 return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
512 return NULL;
515 // container::XEnumerationAccess
517 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
518 throw(uno::RuntimeException)
520 ScUnoGuard aGuard;
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)
528 ScUnoGuard aGuard;
529 if (IsInserted())
530 return SC_AF_FIELD_COUNT; // immer 16 Elemente
531 else
532 return 0;
535 uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
536 throw(lang::IndexOutOfBoundsException,
537 lang::WrappedTargetException, uno::RuntimeException)
539 ScUnoGuard aGuard;
541 if ( nIndex < 0 || nIndex >= getCount() )
542 throw lang::IndexOutOfBoundsException();
544 if (IsInserted())
545 return uno::makeAny(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl((sal_uInt16)nIndex)));
546 return uno::Any();
549 uno::Type SAL_CALL ScAutoFormatObj::getElementType() throw(uno::RuntimeException)
551 ScUnoGuard aGuard;
552 return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); // muss zu getByIndex passen
555 sal_Bool SAL_CALL ScAutoFormatObj::hasElements() throw(uno::RuntimeException)
557 ScUnoGuard aGuard;
558 return ( getCount() != 0 );
561 // container::XNamed
563 rtl::OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException)
565 ScUnoGuard aGuard;
566 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
567 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
569 String aName;
570 (*pFormats)[nFormatIndex]->GetName(aName);
571 return aName;
573 return rtl::OUString();
576 void SAL_CALL ScAutoFormatObj::setName( const rtl::OUString& aNewName )
577 throw(uno::RuntimeException)
579 ScUnoGuard aGuard;
580 String aNewString(aNewName);
581 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
583 sal_uInt16 nDummy;
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);
601 else
603 delete pNew;
604 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
605 nFormatIndex = 0; //! alter Index ist ungueltig
608 else
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)
620 ScUnoGuard aGuard;
621 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
622 return aRef;
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)
631 ScUnoGuard aGuard;
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 );
653 // else Fehler
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)
664 ScUnoGuard aGuard;
665 uno::Any aAny;
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");
673 sal_Bool bValue;
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();
689 else
690 bError = sal_True; // unbekannte Property
692 if (!bError)
693 aAny <<= bValue;
696 return aAny;
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 )
708 //! Listening !!!
711 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
715 void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
717 // spaeter...
720 // beans::XPropertySet
722 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
723 throw(uno::RuntimeException)
725 ScUnoGuard aGuard;
726 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
727 return aRef;
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)
736 ScUnoGuard aGuard;
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 )
753 case ATTR_STACKED:
755 table::CellOrientation eOrient;
756 if( aValue >>= eOrient )
758 switch( eOrient )
760 case table::CellOrientation_STANDARD:
761 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, FALSE ) );
762 break;
763 case table::CellOrientation_TOPBOTTOM:
764 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, FALSE ) );
765 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
766 break;
767 case table::CellOrientation_BOTTOMTOP:
768 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, FALSE ) );
769 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
770 break;
771 case table::CellOrientation_STACKED:
772 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, TRUE ) );
773 break;
774 default:
776 // added to avoid warnings
779 bDone = sal_True;
782 break;
783 default:
784 SfxPoolItem* pNewItem = pItem->Clone();
785 bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
786 if (bDone)
787 pData->PutItem( nFieldIndex, *pNewItem );
788 delete pNewItem;
791 if (bDone)
792 //! Notify fuer andere Objekte?
793 pFormats->SetSaveLater(sal_True);
796 else
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);
814 break;
820 uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
821 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
822 uno::RuntimeException)
824 ScUnoGuard aGuard;
825 uno::Any aVal;
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 )
841 case ATTR_STACKED:
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 );
848 break;
849 default:
850 pItem->QueryValue( aVal, pEntry->nMemberId );
854 else
856 switch (pEntry->nWID)
858 case SC_WID_UNO_TBLBORD:
860 const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
861 if (pItem)
863 SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem)));
864 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
866 table::TableBorder aBorder;
867 ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner );
868 aVal <<= aBorder;
871 break;
876 return aVal;
879 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
881 //------------------------------------------------------------------------