1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 #include "scitems.hxx"
30 #include <editeng/memberids.hrc>
31 #include <tools/debug.hxx>
32 #include <tools/shl.hxx>
33 #include <svl/poolitem.hxx>
34 #include <svx/unomid.hxx>
35 #include "unowids.hxx"
36 #include <rtl/uuid.h>
37 #include <com/sun/star/table/BorderLine.hpp>
38 #include <com/sun/star/table/CellVertJustify.hpp>
39 #include <com/sun/star/table/ShadowLocation.hpp>
40 #include <com/sun/star/table/TableBorder.hpp>
41 #include <com/sun/star/table/ShadowFormat.hpp>
42 #include <com/sun/star/table/CellRangeAddress.hpp>
43 #include <com/sun/star/table/CellContentType.hpp>
44 #include <com/sun/star/table/TableOrientation.hpp>
45 #include <com/sun/star/table/CellHoriJustify.hpp>
46 #include <com/sun/star/util/SortField.hpp>
47 #include <com/sun/star/util/SortFieldType.hpp>
48 #include <com/sun/star/table/CellOrientation.hpp>
49 #include <com/sun/star/table/CellAddress.hpp>
50 #include <com/sun/star/awt/SimpleFontMetric.hpp>
51 #include <com/sun/star/awt/FontWeight.hpp>
52 #include <com/sun/star/awt/FontSlant.hpp>
53 #include <com/sun/star/awt/CharSet.hpp>
54 #include <com/sun/star/awt/FontDescriptor.hpp>
55 #include <com/sun/star/awt/FontWidth.hpp>
56 #include <com/sun/star/awt/XFont.hpp>
57 #include <com/sun/star/awt/FontType.hpp>
58 #include <com/sun/star/awt/FontUnderline.hpp>
59 #include <com/sun/star/awt/FontStrikeout.hpp>
60 #include <com/sun/star/awt/FontFamily.hpp>
61 #include <com/sun/star/awt/FontPitch.hpp>
62
63 #include "afmtuno.hxx"
64 #include "miscuno.hxx"
65 #include "autoform.hxx"
66 #include "unoguard.hxx"
67 #include "scdll.hxx"
68 #include "unonames.hxx"
69 #include "cellsuno.hxx"
70
71 using namespace ::com::sun::star;
72
73 //------------------------------------------------------------------------
74
75 // ein AutoFormat hat immer 16 Eintraege
76 #define SC_AF_FIELD_COUNT 16
77
78 //------------------------------------------------------------------------
79
80 // AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs
81
lcl_GetAutoFormatMap()82 const SfxItemPropertyMapEntry* lcl_GetAutoFormatMap()
83 {
84 static SfxItemPropertyMapEntry aAutoFormatMap_Impl[] =
85 {
86 {MAP_CHAR_LEN(SC_UNONAME_INCBACK), 0, &::getBooleanCppuType(), 0, 0 },
87 {MAP_CHAR_LEN(SC_UNONAME_INCBORD), 0, &::getBooleanCppuType(), 0, 0 },
88 {MAP_CHAR_LEN(SC_UNONAME_INCFONT), 0, &::getBooleanCppuType(), 0, 0 },
89 {MAP_CHAR_LEN(SC_UNONAME_INCJUST), 0, &::getBooleanCppuType(), 0, 0 },
90 {MAP_CHAR_LEN(SC_UNONAME_INCNUM), 0, &::getBooleanCppuType(), 0, 0 },
91 {MAP_CHAR_LEN(SC_UNONAME_INCWIDTH), 0, &::getBooleanCppuType(), 0, 0 },
92 {0,0,0,0,0,0}
93 };
94 return aAutoFormatMap_Impl;
95 }
96
97 //! Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly)
98 //! table::TableBorder ??!?
99
lcl_GetAutoFieldMap()100 const SfxItemPropertyMapEntry* lcl_GetAutoFieldMap()
101 {
102 static SfxItemPropertyMapEntry aAutoFieldMap_Impl[] =
103 {
104 {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR },
105 {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &::getCppuType((const sal_Int32*)0), 0, 0 },
106 {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &::getBooleanCppuType(), 0, 0 },
107 {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT, &::getBooleanCppuType(), 0, MID_CROSSED_OUT },
108 {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &::getCppuType((const sal_Int16*)0), 0, MID_FONT_FAMILY },
109 {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
110 {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
111 {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET },
112 {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
113 {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
114 {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY },
115 {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
116 {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
117 {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME },
118 {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
119 {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
120 {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH },
121 {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
122 {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
123 {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &::getCppuType((rtl::OUString*)0), 0, MID_FONT_STYLE_NAME },
124 {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
125 {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
126 {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS },
127 {MAP_CHAR_LEN(SC_UNONAME_COVER), ATTR_FONT_OVERLINE, &::getCppuType((const sal_Int16*)0), 0, MID_TL_STYLE },
128 {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE },
129 {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE },
130 {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE },
131 {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &::getBooleanCppuType(), 0, 0 },
132 {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &::getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS },
133 {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE, &::getCppuType((const sal_Int16*)0), 0, MID_TL_STYLE },
134 {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT },
135 {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT },
136 {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT },
137 {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &::getCppuType((const table::CellHoriJustify*)0), 0, 0 },
138 {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT },
139 {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &::getBooleanCppuType(), 0, 0 },
140 {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_STACKED, &::getCppuType((const table::CellOrientation*)0), 0, 0 },
141 {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS },
142 {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS },
143 {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS },
144 {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS },
145 {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &::getCppuType((const sal_Int32*)0), 0, 0 },
146 {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &::getCppuType((const table::CellVertJustify*)0), 0, 0 },
147 {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &::getCppuType((const table::CellVertJustify*)0), 0, 0 },
148 {0,0,0,0,0,0}
149 };
150 return aAutoFieldMap_Impl;
151 }
152
153 //------------------------------------------------------------------------
154
155 #define SCAUTOFORMATSOBJ_SERVICE "com.sun.star.sheet.TableAutoFormats"
156
157 SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" )
158 SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" )
159 SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE )
160
161 //------------------------------------------------------------------------
162
lcl_FindAutoFormatIndex(const ScAutoFormat & rFormats,const String & rName,sal_uInt16 & rOutIndex)163 sal_Bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const String& rName, sal_uInt16& rOutIndex )
164 {
165 String aEntryName;
166 sal_uInt16 nCount = rFormats.GetCount();
167 for( sal_uInt16 nPos=0; nPos<nCount; nPos++ )
168 {
169 ScAutoFormatData* pEntry = rFormats[nPos];
170 pEntry->GetName( aEntryName );
171 if ( aEntryName == rName )
172 {
173 rOutIndex = nPos;
174 return sal_True;
175 }
176 }
177 return sal_False; // is nich
178 }
179
180 //------------------------------------------------------------------------
181
ScAutoFormatsObj()182 ScAutoFormatsObj::ScAutoFormatsObj()
183 {
184 //! Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten
185 //! bekannt sein, damit Aenderungen gebroadcasted werden koennen
186 }
187
~ScAutoFormatsObj()188 ScAutoFormatsObj::~ScAutoFormatsObj()
189 {
190 }
191
192 // stuff for exService_...
193
ScAutoFormatsObj_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)194 uno::Reference<uno::XInterface> SAL_CALL ScAutoFormatsObj_CreateInstance(
195 const uno::Reference<lang::XMultiServiceFactory>& )
196 {
197 ScUnoGuard aGuard;
198 ScDLL::Init();
199 static uno::Reference< uno::XInterface > xInst((::cppu::OWeakObject*) new ScAutoFormatsObj);
200 return xInst;
201 }
202
getImplementationName_Static()203 rtl::OUString ScAutoFormatsObj::getImplementationName_Static()
204 {
205 return rtl::OUString::createFromAscii( "stardiv.StarCalc.ScAutoFormatsObj" );
206 }
207
getSupportedServiceNames_Static()208 uno::Sequence<rtl::OUString> ScAutoFormatsObj::getSupportedServiceNames_Static()
209 {
210 uno::Sequence<rtl::OUString> aRet(1);
211 rtl::OUString* pArray = aRet.getArray();
212 pArray[0] = rtl::OUString::createFromAscii( SCAUTOFORMATSOBJ_SERVICE );
213 return aRet;
214 }
215
216 // XTableAutoFormats
217
GetObjectByIndex_Impl(sal_uInt16 nIndex)218 ScAutoFormatObj* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
219 {
220 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
221 if (pFormats && nIndex < pFormats->GetCount())
222 return new ScAutoFormatObj(nIndex);
223
224 return NULL; // falscher Index
225 }
226
GetObjectByName_Impl(const rtl::OUString & aName)227 ScAutoFormatObj* ScAutoFormatsObj::GetObjectByName_Impl(const rtl::OUString& aName)
228 {
229 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
230 if (pFormats)
231 {
232 String aString(aName);
233 sal_uInt16 nIndex;
234 if (lcl_FindAutoFormatIndex( *pFormats, aString, nIndex ))
235 return GetObjectByIndex_Impl(nIndex);
236 }
237 return NULL;
238 }
239
240 // container::XNameContainer
241
insertByName(const rtl::OUString & aName,const uno::Any & aElement)242 void SAL_CALL ScAutoFormatsObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement )
243 {
244 ScUnoGuard aGuard;
245 sal_Bool bDone = sal_False;
246 // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein...
247 uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY);
248 if ( xInterface.is() )
249 {
250 ScAutoFormatObj* pFormatObj = ScAutoFormatObj::getImplementation( xInterface );
251 if ( pFormatObj && !pFormatObj->IsInserted() ) // noch nicht eingefuegt?
252 {
253 String aNameStr(aName);
254 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
255
256 sal_uInt16 nDummy;
257 if (pFormats && !lcl_FindAutoFormatIndex( *pFormats, aNameStr, nDummy ))
258 {
259 ScAutoFormatData* pNew = new ScAutoFormatData();
260 pNew->SetName( aNameStr );
261
262 if (pFormats->Insert( pNew ))
263 {
264 //! Notify fuer andere Objekte
265 pFormats->Save(); // sofort speichern
266
267 sal_uInt16 nNewIndex;
268 if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nNewIndex ))
269 {
270 pFormatObj->InitFormat( nNewIndex ); // kann jetzt benutzt werden
271 bDone = sal_True;
272 }
273 }
274 else
275 {
276 delete pNew;
277 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
278 throw uno::RuntimeException();
279 }
280 }
281 else
282 {
283 throw container::ElementExistException();
284 }
285 }
286 }
287
288 if (!bDone)
289 {
290 // other errors are handled above
291 throw lang::IllegalArgumentException();
292 }
293 }
294
replaceByName(const rtl::OUString & aName,const uno::Any & aElement)295 void SAL_CALL ScAutoFormatsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement )
296 {
297 ScUnoGuard aGuard;
298 //! zusammenfassen?
299 removeByName( aName );
300 insertByName( aName, aElement );
301 }
302
removeByName(const rtl::OUString & aName)303 void SAL_CALL ScAutoFormatsObj::removeByName( const rtl::OUString& aName )
304 {
305 ScUnoGuard aGuard;
306 String aNameStr(aName);
307 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
308
309 sal_uInt16 nIndex;
310 if (pFormats && lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex ))
311 {
312 pFormats->AtFree( nIndex );
313
314 //! Notify fuer andere Objekte
315 pFormats->Save(); // sofort speichern
316 }
317 else
318 {
319 throw container::NoSuchElementException();
320 }
321 }
322
323 // container::XEnumerationAccess
324
createEnumeration()325 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration()
326 {
327 ScUnoGuard aGuard;
328 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
329 }
330
331 // container::XIndexAccess
332
getCount()333 sal_Int32 SAL_CALL ScAutoFormatsObj::getCount()
334 {
335 ScUnoGuard aGuard;
336 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
337 if (pFormats)
338 return pFormats->GetCount();
339
340 return 0;
341 }
342
getByIndex(sal_Int32 nIndex)343 uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex )
344 {
345 ScUnoGuard aGuard;
346 uno::Reference< container::XNamed > xFormat(GetObjectByIndex_Impl((sal_uInt16)nIndex));
347 if (!xFormat.is())
348 throw lang::IndexOutOfBoundsException();
349 return uno::makeAny(xFormat);
350 }
351
getElementType()352 uno::Type SAL_CALL ScAutoFormatsObj::getElementType()
353 {
354 ScUnoGuard aGuard;
355 return ::getCppuType((const uno::Reference< container::XNamed >*)0); // muss zu getByIndex passen
356 }
357
hasElements()358 sal_Bool SAL_CALL ScAutoFormatsObj::hasElements()
359 {
360 ScUnoGuard aGuard;
361 return ( getCount() != 0 );
362 }
363
364 // container::XNameAccess
365
getByName(const rtl::OUString & aName)366 uno::Any SAL_CALL ScAutoFormatsObj::getByName( const rtl::OUString& aName )
367 {
368 ScUnoGuard aGuard;
369 uno::Reference< container::XNamed > xFormat(GetObjectByName_Impl(aName));
370 if (!xFormat.is())
371 throw container::NoSuchElementException();
372 return uno::makeAny(xFormat);
373 }
374
getElementNames()375 uno::Sequence<rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames()
376 {
377 ScUnoGuard aGuard;
378 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
379 if (pFormats)
380 {
381 String aName;
382 sal_uInt16 nCount = pFormats->GetCount();
383 uno::Sequence<rtl::OUString> aSeq(nCount);
384 rtl::OUString* pAry = aSeq.getArray();
385 for (sal_uInt16 i=0; i<nCount; i++)
386 {
387 (*pFormats)[i]->GetName(aName);
388 pAry[i] = aName;
389 }
390 return aSeq;
391 }
392 return uno::Sequence<rtl::OUString>(0);
393 }
394
hasByName(const rtl::OUString & aName)395 sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const rtl::OUString& aName )
396 {
397 ScUnoGuard aGuard;
398 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
399 if (pFormats)
400 {
401 String aString(aName);
402 sal_uInt16 nDummy;
403 return lcl_FindAutoFormatIndex( *pFormats, aString, nDummy );
404 }
405 return sal_False;
406 }
407
408 //------------------------------------------------------------------------
409
ScAutoFormatObj(sal_uInt16 nIndex)410 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) :
411 aPropSet( lcl_GetAutoFormatMap() ),
412 nFormatIndex( nIndex )
413 {
414 //! Listening !!!
415 }
416
~ScAutoFormatObj()417 ScAutoFormatObj::~ScAutoFormatObj()
418 {
419 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen
420 // gespeichert, damit sie z.B. im Writer sichtbar sind
421
422 if (IsInserted())
423 {
424 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
425 if ( pFormats && pFormats->IsSaveLater() )
426 pFormats->Save();
427
428 // Save() setzt SaveLater Flag zurueck
429 }
430 }
431
InitFormat(sal_uInt16 nNewIndex)432 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex )
433 {
434 DBG_ASSERT( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat mehrfach" );
435 nFormatIndex = nNewIndex;
436 //! Listening !!!
437 }
438
439 // XUnoTunnel
440
getSomething(const uno::Sequence<sal_Int8> & rId)441 sal_Int64 SAL_CALL ScAutoFormatObj::getSomething(
442 const uno::Sequence<sal_Int8 >& rId )
443 {
444 if ( rId.getLength() == 16 &&
445 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
446 rId.getConstArray(), 16 ) )
447 {
448 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
449 }
450 return 0;
451 }
452
453 // static
getUnoTunnelId()454 const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId()
455 {
456 static uno::Sequence<sal_Int8> * pSeq = 0;
457 if( !pSeq )
458 {
459 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
460 if( !pSeq )
461 {
462 static uno::Sequence< sal_Int8 > aSeq( 16 );
463 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
464 pSeq = &aSeq;
465 }
466 }
467 return *pSeq;
468 }
469
470 // static
getImplementation(const uno::Reference<uno::XInterface> xObj)471 ScAutoFormatObj* ScAutoFormatObj::getImplementation(
472 const uno::Reference<uno::XInterface> xObj )
473 {
474 ScAutoFormatObj* pRet = NULL;
475 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
476 if (xUT.is())
477 pRet = reinterpret_cast<ScAutoFormatObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
478 return pRet;
479 }
480
Notify(SfxBroadcaster &,const SfxHint &)481 void ScAutoFormatObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
482 {
483 // spaeter...
484 }
485
486 // XTableAutoFormat
487
GetObjectByIndex_Impl(sal_uInt16 nIndex)488 ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex)
489 {
490 if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT )
491 return new ScAutoFormatFieldObj( nFormatIndex, nIndex );
492
493 return NULL;
494 }
495
496 // container::XEnumerationAccess
497
createEnumeration()498 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration()
499 {
500 ScUnoGuard aGuard;
501 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration")));
502 }
503
504 // container::XIndexAccess
505
getCount()506 sal_Int32 SAL_CALL ScAutoFormatObj::getCount()
507 {
508 ScUnoGuard aGuard;
509 if (IsInserted())
510 return SC_AF_FIELD_COUNT; // immer 16 Elemente
511 else
512 return 0;
513 }
514
getByIndex(sal_Int32 nIndex)515 uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex )
516 {
517 ScUnoGuard aGuard;
518
519 if ( nIndex < 0 || nIndex >= getCount() )
520 throw lang::IndexOutOfBoundsException();
521
522 if (IsInserted())
523 return uno::makeAny(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl((sal_uInt16)nIndex)));
524 return uno::Any();
525 }
526
getElementType()527 uno::Type SAL_CALL ScAutoFormatObj::getElementType()
528 {
529 ScUnoGuard aGuard;
530 return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); // muss zu getByIndex passen
531 }
532
hasElements()533 sal_Bool SAL_CALL ScAutoFormatObj::hasElements()
534 {
535 ScUnoGuard aGuard;
536 return ( getCount() != 0 );
537 }
538
539 // container::XNamed
540
getName()541 rtl::OUString SAL_CALL ScAutoFormatObj::getName()
542 {
543 ScUnoGuard aGuard;
544 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
545 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
546 {
547 String aName;
548 (*pFormats)[nFormatIndex]->GetName(aName);
549 return aName;
550 }
551 return rtl::OUString();
552 }
553
setName(const rtl::OUString & aNewName)554 void SAL_CALL ScAutoFormatObj::setName( const rtl::OUString& aNewName )
555 {
556 ScUnoGuard aGuard;
557 String aNewString(aNewName);
558 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
559
560 sal_uInt16 nDummy;
561 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount() &&
562 !lcl_FindAutoFormatIndex( *pFormats, aNewString, nDummy ))
563 {
564 ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
565 DBG_ASSERT(pData,"AutoFormat Daten nicht da");
566
567 ScAutoFormatData* pNew = new ScAutoFormatData(*pData);
568 pNew->SetName( aNewString );
569
570 pFormats->AtFree( nFormatIndex );
571 if (pFormats->Insert( pNew ))
572 {
573 nFormatIndex = pFormats->IndexOf( pNew ); // ist evtl. anders einsortiert...
574
575 //! Notify fuer andere Objekte
576 pFormats->SetSaveLater(sal_True);
577 }
578 else
579 {
580 delete pNew;
581 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden");
582 nFormatIndex = 0; //! alter Index ist ungueltig
583 }
584 }
585 else
586 {
587 // not inserted or name exists
588 throw uno::RuntimeException();
589 }
590 }
591
592 // beans::XPropertySet
593
getPropertySetInfo()594 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo()
595 {
596 ScUnoGuard aGuard;
597 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
598 return aRef;
599 }
600
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)601 void SAL_CALL ScAutoFormatObj::setPropertyValue(
602 const rtl::OUString& aPropertyName, const uno::Any& aValue )
603 {
604 ScUnoGuard aGuard;
605 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
606 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
607 {
608 ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
609 DBG_ASSERT(pData,"AutoFormat Daten nicht da");
610
611 String aPropString(aPropertyName);
612 sal_Bool bBool = sal_Bool();
613 if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ) && (aValue >>= bBool))
614 pData->SetIncludeBackground( bBool );
615 else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ) && (aValue >>= bBool))
616 pData->SetIncludeFrame( bBool );
617 else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ) && (aValue >>= bBool))
618 pData->SetIncludeFont( bBool );
619 else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ) && (aValue >>= bBool))
620 pData->SetIncludeJustify( bBool );
621 else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ) && (aValue >>= bBool))
622 pData->SetIncludeValueFormat( bBool );
623 else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ) && (aValue >>= bBool))
624 pData->SetIncludeWidthHeight( bBool );
625
626 // else Fehler
627
628 //! Notify fuer andere Objekte
629 pFormats->SetSaveLater(sal_True);
630 }
631 }
632
getPropertyValue(const rtl::OUString & aPropertyName)633 uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const rtl::OUString& aPropertyName )
634 {
635 ScUnoGuard aGuard;
636 uno::Any aAny;
637
638 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
639 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount())
640 {
641 ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
642 DBG_ASSERT(pData,"AutoFormat Daten nicht da");
643
644 sal_Bool bValue;
645 sal_Bool bError = sal_False;
646
647 String aPropString(aPropertyName);
648 if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ))
649 bValue = pData->GetIncludeBackground();
650 else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ))
651 bValue = pData->GetIncludeFrame();
652 else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ))
653 bValue = pData->GetIncludeFont();
654 else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ))
655 bValue = pData->GetIncludeJustify();
656 else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ))
657 bValue = pData->GetIncludeValueFormat();
658 else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ))
659 bValue = pData->GetIncludeWidthHeight();
660 else
661 bError = sal_True; // unbekannte Property
662
663 if (!bError)
664 aAny <<= bValue;
665 }
666
667 return aAny;
668 }
669
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScAutoFormatObj)670 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj )
671
672 //------------------------------------------------------------------------
673
674 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) :
675 aPropSet( lcl_GetAutoFieldMap() ),
676 nFormatIndex( nFormat ),
677 nFieldIndex( nField )
678 {
679 //! Listening !!!
680 }
681
~ScAutoFormatFieldObj()682 ScAutoFormatFieldObj::~ScAutoFormatFieldObj()
683 {
684 }
685
Notify(SfxBroadcaster &,const SfxHint &)686 void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ )
687 {
688 // spaeter...
689 }
690
691 // beans::XPropertySet
692
getPropertySetInfo()693 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo()
694 {
695 ScUnoGuard aGuard;
696 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
697 return aRef;
698 }
699
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)700 void SAL_CALL ScAutoFormatFieldObj::setPropertyValue(
701 const rtl::OUString& aPropertyName, const uno::Any& aValue )
702 {
703 ScUnoGuard aGuard;
704 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
705 const SfxItemPropertySimpleEntry* pEntry =
706 aPropSet.getPropertyMap()->getByName( aPropertyName );
707
708 if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() )
709 {
710 ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
711
712 if ( IsScItemWid( pEntry->nWID ) )
713 {
714 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
715 {
716 sal_Bool bDone = sal_False;
717
718 switch( pEntry->nWID )
719 {
720 case ATTR_STACKED:
721 {
722 table::CellOrientation eOrient;
723 if( aValue >>= eOrient )
724 {
725 switch( eOrient )
726 {
727 case table::CellOrientation_STANDARD:
728 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
729 break;
730 case table::CellOrientation_TOPBOTTOM:
731 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
732 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) );
733 break;
734 case table::CellOrientation_BOTTOMTOP:
735 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) );
736 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) );
737 break;
738 case table::CellOrientation_STACKED:
739 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_True ) );
740 break;
741 default:
742 {
743 // added to avoid warnings
744 }
745 }
746 bDone = sal_True;
747 }
748 }
749 break;
750 default:
751 SfxPoolItem* pNewItem = pItem->Clone();
752 bDone = pNewItem->PutValue( aValue, pEntry->nMemberId );
753 if (bDone)
754 pData->PutItem( nFieldIndex, *pNewItem );
755 delete pNewItem;
756 }
757
758 if (bDone)
759 //! Notify fuer andere Objekte?
760 pFormats->SetSaveLater(sal_True);
761 }
762 }
763 else
764 {
765 switch (pEntry->nWID)
766 {
767 case SC_WID_UNO_TBLBORD:
768 {
769 table::TableBorder aBorder;
770 if ( aValue >>= aBorder ) // empty = nothing to do
771 {
772 SvxBoxItem aOuter(ATTR_BORDER);
773 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
774 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder );
775 pData->PutItem( nFieldIndex, aOuter );
776
777 //! Notify fuer andere Objekte?
778 pFormats->SetSaveLater(sal_True);
779 }
780 }
781 break;
782 }
783 }
784 }
785 }
786
getPropertyValue(const rtl::OUString & aPropertyName)787 uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString& aPropertyName )
788 {
789 ScUnoGuard aGuard;
790 uno::Any aVal;
791
792 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat();
793 const SfxItemPropertySimpleEntry* pEntry =
794 aPropSet.getPropertyMap()->getByName( aPropertyName );
795
796 if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() )
797 {
798 const ScAutoFormatData* pData = (*pFormats)[nFormatIndex];
799
800 if ( IsScItemWid( pEntry->nWID ) )
801 {
802 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) )
803 {
804 switch( pEntry->nWID )
805 {
806 case ATTR_STACKED:
807 {
808 const SfxInt32Item* pRotItem = (const SfxInt32Item*)pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE );
809 sal_Int32 nRot = pRotItem ? pRotItem->GetValue() : 0;
810 sal_Bool bStacked = ((const SfxBoolItem*)pItem)->GetValue();
811 SvxOrientationItem( nRot, bStacked, 0 ).QueryValue( aVal );
812 }
813 break;
814 default:
815 pItem->QueryValue( aVal, pEntry->nMemberId );
816 }
817 }
818 }
819 else
820 {
821 switch (pEntry->nWID)
822 {
823 case SC_WID_UNO_TBLBORD:
824 {
825 const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER);
826 if (pItem)
827 {
828 SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem)));
829 SvxBoxInfoItem aInner(ATTR_BORDER_INNER);
830
831 table::TableBorder aBorder;
832 ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner );
833 aVal <<= aBorder;
834 }
835 }
836 break;
837 }
838 }
839 }
840
841 return aVal;
842 }
843
844 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj )
845
846 //------------------------------------------------------------------------
847