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 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 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 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 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 188 ScAutoFormatsObj::~ScAutoFormatsObj() 189 { 190 } 191 192 // stuff for exService_... 193 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 203 rtl::OUString ScAutoFormatsObj::getImplementationName_Static() 204 { 205 return rtl::OUString::createFromAscii( "stardiv.StarCalc.ScAutoFormatsObj" ); 206 } 207 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 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 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 242 void SAL_CALL ScAutoFormatsObj::insertByName( const rtl::OUString& aName, const uno::Any& aElement ) 243 throw(lang::IllegalArgumentException, container::ElementExistException, 244 lang::WrappedTargetException, uno::RuntimeException) 245 { 246 ScUnoGuard aGuard; 247 sal_Bool bDone = sal_False; 248 // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein... 249 uno::Reference< uno::XInterface > xInterface(aElement, uno::UNO_QUERY); 250 if ( xInterface.is() ) 251 { 252 ScAutoFormatObj* pFormatObj = ScAutoFormatObj::getImplementation( xInterface ); 253 if ( pFormatObj && !pFormatObj->IsInserted() ) // noch nicht eingefuegt? 254 { 255 String aNameStr(aName); 256 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 257 258 sal_uInt16 nDummy; 259 if (pFormats && !lcl_FindAutoFormatIndex( *pFormats, aNameStr, nDummy )) 260 { 261 ScAutoFormatData* pNew = new ScAutoFormatData(); 262 pNew->SetName( aNameStr ); 263 264 if (pFormats->Insert( pNew )) 265 { 266 //! Notify fuer andere Objekte 267 pFormats->Save(); // sofort speichern 268 269 sal_uInt16 nNewIndex; 270 if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nNewIndex )) 271 { 272 pFormatObj->InitFormat( nNewIndex ); // kann jetzt benutzt werden 273 bDone = sal_True; 274 } 275 } 276 else 277 { 278 delete pNew; 279 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden"); 280 throw uno::RuntimeException(); 281 } 282 } 283 else 284 { 285 throw container::ElementExistException(); 286 } 287 } 288 } 289 290 if (!bDone) 291 { 292 // other errors are handled above 293 throw lang::IllegalArgumentException(); 294 } 295 } 296 297 void SAL_CALL ScAutoFormatsObj::replaceByName( const rtl::OUString& aName, const uno::Any& aElement ) 298 throw(lang::IllegalArgumentException, container::NoSuchElementException, 299 lang::WrappedTargetException, uno::RuntimeException) 300 { 301 ScUnoGuard aGuard; 302 //! zusammenfassen? 303 removeByName( aName ); 304 insertByName( aName, aElement ); 305 } 306 307 void SAL_CALL ScAutoFormatsObj::removeByName( const rtl::OUString& aName ) 308 throw(container::NoSuchElementException, 309 lang::WrappedTargetException, uno::RuntimeException) 310 { 311 ScUnoGuard aGuard; 312 String aNameStr(aName); 313 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 314 315 sal_uInt16 nIndex; 316 if (pFormats && lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex )) 317 { 318 pFormats->AtFree( nIndex ); 319 320 //! Notify fuer andere Objekte 321 pFormats->Save(); // sofort speichern 322 } 323 else 324 { 325 throw container::NoSuchElementException(); 326 } 327 } 328 329 // container::XEnumerationAccess 330 331 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration() 332 throw(uno::RuntimeException) 333 { 334 ScUnoGuard aGuard; 335 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration"))); 336 } 337 338 // container::XIndexAccess 339 340 sal_Int32 SAL_CALL ScAutoFormatsObj::getCount() throw(uno::RuntimeException) 341 { 342 ScUnoGuard aGuard; 343 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 344 if (pFormats) 345 return pFormats->GetCount(); 346 347 return 0; 348 } 349 350 uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex ) 351 throw(lang::IndexOutOfBoundsException, 352 lang::WrappedTargetException, uno::RuntimeException) 353 { 354 ScUnoGuard aGuard; 355 uno::Reference< container::XNamed > xFormat(GetObjectByIndex_Impl((sal_uInt16)nIndex)); 356 if (!xFormat.is()) 357 throw lang::IndexOutOfBoundsException(); 358 return uno::makeAny(xFormat); 359 } 360 361 uno::Type SAL_CALL ScAutoFormatsObj::getElementType() throw(uno::RuntimeException) 362 { 363 ScUnoGuard aGuard; 364 return ::getCppuType((const uno::Reference< container::XNamed >*)0); // muss zu getByIndex passen 365 } 366 367 sal_Bool SAL_CALL ScAutoFormatsObj::hasElements() throw(uno::RuntimeException) 368 { 369 ScUnoGuard aGuard; 370 return ( getCount() != 0 ); 371 } 372 373 // container::XNameAccess 374 375 uno::Any SAL_CALL ScAutoFormatsObj::getByName( const rtl::OUString& aName ) 376 throw(container::NoSuchElementException, 377 lang::WrappedTargetException, uno::RuntimeException) 378 { 379 ScUnoGuard aGuard; 380 uno::Reference< container::XNamed > xFormat(GetObjectByName_Impl(aName)); 381 if (!xFormat.is()) 382 throw container::NoSuchElementException(); 383 return uno::makeAny(xFormat); 384 } 385 386 uno::Sequence<rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames() 387 throw(uno::RuntimeException) 388 { 389 ScUnoGuard aGuard; 390 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 391 if (pFormats) 392 { 393 String aName; 394 sal_uInt16 nCount = pFormats->GetCount(); 395 uno::Sequence<rtl::OUString> aSeq(nCount); 396 rtl::OUString* pAry = aSeq.getArray(); 397 for (sal_uInt16 i=0; i<nCount; i++) 398 { 399 (*pFormats)[i]->GetName(aName); 400 pAry[i] = aName; 401 } 402 return aSeq; 403 } 404 return uno::Sequence<rtl::OUString>(0); 405 } 406 407 sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const rtl::OUString& aName ) 408 throw(uno::RuntimeException) 409 { 410 ScUnoGuard aGuard; 411 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 412 if (pFormats) 413 { 414 String aString(aName); 415 sal_uInt16 nDummy; 416 return lcl_FindAutoFormatIndex( *pFormats, aString, nDummy ); 417 } 418 return sal_False; 419 } 420 421 //------------------------------------------------------------------------ 422 423 ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) : 424 aPropSet( lcl_GetAutoFormatMap() ), 425 nFormatIndex( nIndex ) 426 { 427 //! Listening !!! 428 } 429 430 ScAutoFormatObj::~ScAutoFormatObj() 431 { 432 // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen 433 // gespeichert, damit sie z.B. im Writer sichtbar sind 434 435 if (IsInserted()) 436 { 437 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 438 if ( pFormats && pFormats->IsSaveLater() ) 439 pFormats->Save(); 440 441 // Save() setzt SaveLater Flag zurueck 442 } 443 } 444 445 void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex ) 446 { 447 DBG_ASSERT( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat mehrfach" ); 448 nFormatIndex = nNewIndex; 449 //! Listening !!! 450 } 451 452 // XUnoTunnel 453 454 sal_Int64 SAL_CALL ScAutoFormatObj::getSomething( 455 const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 456 { 457 if ( rId.getLength() == 16 && 458 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 459 rId.getConstArray(), 16 ) ) 460 { 461 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); 462 } 463 return 0; 464 } 465 466 // static 467 const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId() 468 { 469 static uno::Sequence<sal_Int8> * pSeq = 0; 470 if( !pSeq ) 471 { 472 osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 473 if( !pSeq ) 474 { 475 static uno::Sequence< sal_Int8 > aSeq( 16 ); 476 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 477 pSeq = &aSeq; 478 } 479 } 480 return *pSeq; 481 } 482 483 // static 484 ScAutoFormatObj* ScAutoFormatObj::getImplementation( 485 const uno::Reference<uno::XInterface> xObj ) 486 { 487 ScAutoFormatObj* pRet = NULL; 488 uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 489 if (xUT.is()) 490 pRet = reinterpret_cast<ScAutoFormatObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId()))); 491 return pRet; 492 } 493 494 void ScAutoFormatObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ ) 495 { 496 // spaeter... 497 } 498 499 // XTableAutoFormat 500 501 ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) 502 { 503 if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT ) 504 return new ScAutoFormatFieldObj( nFormatIndex, nIndex ); 505 506 return NULL; 507 } 508 509 // container::XEnumerationAccess 510 511 uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration() 512 throw(uno::RuntimeException) 513 { 514 ScUnoGuard aGuard; 515 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration"))); 516 } 517 518 // container::XIndexAccess 519 520 sal_Int32 SAL_CALL ScAutoFormatObj::getCount() throw(uno::RuntimeException) 521 { 522 ScUnoGuard aGuard; 523 if (IsInserted()) 524 return SC_AF_FIELD_COUNT; // immer 16 Elemente 525 else 526 return 0; 527 } 528 529 uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex ) 530 throw(lang::IndexOutOfBoundsException, 531 lang::WrappedTargetException, uno::RuntimeException) 532 { 533 ScUnoGuard aGuard; 534 535 if ( nIndex < 0 || nIndex >= getCount() ) 536 throw lang::IndexOutOfBoundsException(); 537 538 if (IsInserted()) 539 return uno::makeAny(uno::Reference< beans::XPropertySet >(GetObjectByIndex_Impl((sal_uInt16)nIndex))); 540 return uno::Any(); 541 } 542 543 uno::Type SAL_CALL ScAutoFormatObj::getElementType() throw(uno::RuntimeException) 544 { 545 ScUnoGuard aGuard; 546 return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); // muss zu getByIndex passen 547 } 548 549 sal_Bool SAL_CALL ScAutoFormatObj::hasElements() throw(uno::RuntimeException) 550 { 551 ScUnoGuard aGuard; 552 return ( getCount() != 0 ); 553 } 554 555 // container::XNamed 556 557 rtl::OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException) 558 { 559 ScUnoGuard aGuard; 560 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 561 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) 562 { 563 String aName; 564 (*pFormats)[nFormatIndex]->GetName(aName); 565 return aName; 566 } 567 return rtl::OUString(); 568 } 569 570 void SAL_CALL ScAutoFormatObj::setName( const rtl::OUString& aNewName ) 571 throw(uno::RuntimeException) 572 { 573 ScUnoGuard aGuard; 574 String aNewString(aNewName); 575 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 576 577 sal_uInt16 nDummy; 578 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount() && 579 !lcl_FindAutoFormatIndex( *pFormats, aNewString, nDummy )) 580 { 581 ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; 582 DBG_ASSERT(pData,"AutoFormat Daten nicht da"); 583 584 ScAutoFormatData* pNew = new ScAutoFormatData(*pData); 585 pNew->SetName( aNewString ); 586 587 pFormats->AtFree( nFormatIndex ); 588 if (pFormats->Insert( pNew )) 589 { 590 nFormatIndex = pFormats->IndexOf( pNew ); // ist evtl. anders einsortiert... 591 592 //! Notify fuer andere Objekte 593 pFormats->SetSaveLater(sal_True); 594 } 595 else 596 { 597 delete pNew; 598 DBG_ERROR("AutoFormat konnte nicht eingefuegt werden"); 599 nFormatIndex = 0; //! alter Index ist ungueltig 600 } 601 } 602 else 603 { 604 // not inserted or name exists 605 throw uno::RuntimeException(); 606 } 607 } 608 609 // beans::XPropertySet 610 611 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo() 612 throw(uno::RuntimeException) 613 { 614 ScUnoGuard aGuard; 615 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() )); 616 return aRef; 617 } 618 619 void SAL_CALL ScAutoFormatObj::setPropertyValue( 620 const rtl::OUString& aPropertyName, const uno::Any& aValue ) 621 throw(beans::UnknownPropertyException, beans::PropertyVetoException, 622 lang::IllegalArgumentException, lang::WrappedTargetException, 623 uno::RuntimeException) 624 { 625 ScUnoGuard aGuard; 626 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 627 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) 628 { 629 ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; 630 DBG_ASSERT(pData,"AutoFormat Daten nicht da"); 631 632 String aPropString(aPropertyName); 633 sal_Bool bBool = sal_Bool(); 634 if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ) && (aValue >>= bBool)) 635 pData->SetIncludeBackground( bBool ); 636 else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ) && (aValue >>= bBool)) 637 pData->SetIncludeFrame( bBool ); 638 else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ) && (aValue >>= bBool)) 639 pData->SetIncludeFont( bBool ); 640 else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ) && (aValue >>= bBool)) 641 pData->SetIncludeJustify( bBool ); 642 else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ) && (aValue >>= bBool)) 643 pData->SetIncludeValueFormat( bBool ); 644 else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ) && (aValue >>= bBool)) 645 pData->SetIncludeWidthHeight( bBool ); 646 647 // else Fehler 648 649 //! Notify fuer andere Objekte 650 pFormats->SetSaveLater(sal_True); 651 } 652 } 653 654 uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const rtl::OUString& aPropertyName ) 655 throw(beans::UnknownPropertyException, lang::WrappedTargetException, 656 uno::RuntimeException) 657 { 658 ScUnoGuard aGuard; 659 uno::Any aAny; 660 661 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 662 if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) 663 { 664 ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; 665 DBG_ASSERT(pData,"AutoFormat Daten nicht da"); 666 667 sal_Bool bValue; 668 sal_Bool bError = sal_False; 669 670 String aPropString(aPropertyName); 671 if (aPropString.EqualsAscii( SC_UNONAME_INCBACK )) 672 bValue = pData->GetIncludeBackground(); 673 else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD )) 674 bValue = pData->GetIncludeFrame(); 675 else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT )) 676 bValue = pData->GetIncludeFont(); 677 else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST )) 678 bValue = pData->GetIncludeJustify(); 679 else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM )) 680 bValue = pData->GetIncludeValueFormat(); 681 else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH )) 682 bValue = pData->GetIncludeWidthHeight(); 683 else 684 bError = sal_True; // unbekannte Property 685 686 if (!bError) 687 aAny <<= bValue; 688 } 689 690 return aAny; 691 } 692 693 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj ) 694 695 //------------------------------------------------------------------------ 696 697 ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) : 698 aPropSet( lcl_GetAutoFieldMap() ), 699 nFormatIndex( nFormat ), 700 nFieldIndex( nField ) 701 { 702 //! Listening !!! 703 } 704 705 ScAutoFormatFieldObj::~ScAutoFormatFieldObj() 706 { 707 } 708 709 void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /* rBC */, const SfxHint& /* rHint */ ) 710 { 711 // spaeter... 712 } 713 714 // beans::XPropertySet 715 716 uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo() 717 throw(uno::RuntimeException) 718 { 719 ScUnoGuard aGuard; 720 static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( aPropSet.getPropertyMap() )); 721 return aRef; 722 } 723 724 void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( 725 const rtl::OUString& aPropertyName, const uno::Any& aValue ) 726 throw(beans::UnknownPropertyException, beans::PropertyVetoException, 727 lang::IllegalArgumentException, lang::WrappedTargetException, 728 uno::RuntimeException) 729 { 730 ScUnoGuard aGuard; 731 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 732 const SfxItemPropertySimpleEntry* pEntry = 733 aPropSet.getPropertyMap()->getByName( aPropertyName ); 734 735 if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() ) 736 { 737 ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; 738 739 if ( IsScItemWid( pEntry->nWID ) ) 740 { 741 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) ) 742 { 743 sal_Bool bDone = sal_False; 744 745 switch( pEntry->nWID ) 746 { 747 case ATTR_STACKED: 748 { 749 table::CellOrientation eOrient; 750 if( aValue >>= eOrient ) 751 { 752 switch( eOrient ) 753 { 754 case table::CellOrientation_STANDARD: 755 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) ); 756 break; 757 case table::CellOrientation_TOPBOTTOM: 758 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) ); 759 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 27000 ) ); 760 break; 761 case table::CellOrientation_BOTTOMTOP: 762 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_False ) ); 763 pData->PutItem( nFieldIndex, SfxInt32Item( ATTR_ROTATE_VALUE, 9000 ) ); 764 break; 765 case table::CellOrientation_STACKED: 766 pData->PutItem( nFieldIndex, SfxBoolItem( ATTR_STACKED, sal_True ) ); 767 break; 768 default: 769 { 770 // added to avoid warnings 771 } 772 } 773 bDone = sal_True; 774 } 775 } 776 break; 777 default: 778 SfxPoolItem* pNewItem = pItem->Clone(); 779 bDone = pNewItem->PutValue( aValue, pEntry->nMemberId ); 780 if (bDone) 781 pData->PutItem( nFieldIndex, *pNewItem ); 782 delete pNewItem; 783 } 784 785 if (bDone) 786 //! Notify fuer andere Objekte? 787 pFormats->SetSaveLater(sal_True); 788 } 789 } 790 else 791 { 792 switch (pEntry->nWID) 793 { 794 case SC_WID_UNO_TBLBORD: 795 { 796 table::TableBorder aBorder; 797 if ( aValue >>= aBorder ) // empty = nothing to do 798 { 799 SvxBoxItem aOuter(ATTR_BORDER); 800 SvxBoxInfoItem aInner(ATTR_BORDER_INNER); 801 ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder ); 802 pData->PutItem( nFieldIndex, aOuter ); 803 804 //! Notify fuer andere Objekte? 805 pFormats->SetSaveLater(sal_True); 806 } 807 } 808 break; 809 } 810 } 811 } 812 } 813 814 uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const rtl::OUString& aPropertyName ) 815 throw(beans::UnknownPropertyException, lang::WrappedTargetException, 816 uno::RuntimeException) 817 { 818 ScUnoGuard aGuard; 819 uno::Any aVal; 820 821 ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); 822 const SfxItemPropertySimpleEntry* pEntry = 823 aPropSet.getPropertyMap()->getByName( aPropertyName ); 824 825 if ( pEntry && pEntry->nWID && pFormats && nFormatIndex < pFormats->GetCount() ) 826 { 827 const ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; 828 829 if ( IsScItemWid( pEntry->nWID ) ) 830 { 831 if( const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pEntry->nWID ) ) 832 { 833 switch( pEntry->nWID ) 834 { 835 case ATTR_STACKED: 836 { 837 const SfxInt32Item* pRotItem = (const SfxInt32Item*)pData->GetItem( nFieldIndex, ATTR_ROTATE_VALUE ); 838 sal_Int32 nRot = pRotItem ? pRotItem->GetValue() : 0; 839 sal_Bool bStacked = ((const SfxBoolItem*)pItem)->GetValue(); 840 SvxOrientationItem( nRot, bStacked, 0 ).QueryValue( aVal ); 841 } 842 break; 843 default: 844 pItem->QueryValue( aVal, pEntry->nMemberId ); 845 } 846 } 847 } 848 else 849 { 850 switch (pEntry->nWID) 851 { 852 case SC_WID_UNO_TBLBORD: 853 { 854 const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER); 855 if (pItem) 856 { 857 SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem))); 858 SvxBoxInfoItem aInner(ATTR_BORDER_INNER); 859 860 table::TableBorder aBorder; 861 ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner ); 862 aVal <<= aBorder; 863 } 864 } 865 break; 866 } 867 } 868 } 869 870 return aVal; 871 } 872 873 SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj ) 874 875 //------------------------------------------------------------------------ 876 877 878 879