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_svx.hxx" 26 27 #include <com/sun/star/drawing/BitmapMode.hpp> 28 #include <com/sun/star/style/XStyle.hpp> 29 #include <com/sun/star/text/WritingMode.hpp> 30 #include <com/sun/star/table/TableBorder.hpp> 31 32 #include <cppuhelper/typeprovider.hxx> 33 #include <svl/style.hxx> 34 #include <svl/itemset.hxx> 35 36 #include <vos/mutex.hxx> 37 #include <vcl/svapp.hxx> 38 39 #include "svx/sdr/properties/textproperties.hxx" 40 #include "editeng/outlobj.hxx" 41 #include "editeng/writingmodeitem.hxx" 42 #include "svx/svdotable.hxx" 43 #include "svx/svdoutl.hxx" 44 #include "svx/unoshtxt.hxx" 45 #include "svx/svdmodel.hxx" 46 47 #include "tableundo.hxx" 48 #include "cell.hxx" 49 #include "svx/svdotable.hxx" 50 #include "svx/svdoutl.hxx" 51 #include "svx/unoshtxt.hxx" 52 #include "svx/unoshprp.hxx" 53 #include "svx/unoshape.hxx" 54 #include "editeng/editobj.hxx" 55 #include "editeng/boxitem.hxx" 56 #include "svx/xflbstit.hxx" 57 #include "svx/xflbmtit.hxx" 58 #include <svx/svdpool.hxx> 59 60 // ----------------------------------------------------------------------------- 61 62 using ::rtl::OUString; 63 using ::vos::OGuard; 64 using namespace ::com::sun::star::uno; 65 using namespace ::com::sun::star::beans; 66 using namespace ::com::sun::star::lang; 67 using namespace ::com::sun::star::text; 68 using namespace ::com::sun::star::table; 69 using namespace ::com::sun::star::drawing; 70 using namespace ::com::sun::star::style; 71 using namespace ::com::sun::star::container; 72 73 // ----------------------------------------------------------------------------- 74 75 static const SvxItemPropertySet* ImplGetSvxCellPropertySet() 76 { 77 // Propertymap fuer einen Outliner Text 78 static const SfxItemPropertyMapEntry aSvxCellPropertyMap[] = 79 { 80 FILL_PROPERTIES 81 // { MAP_CHAR_LEN("HasLevels"), OWN_ATTR_HASLEVELS, &::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::READONLY, 0}, 82 { MAP_CHAR_LEN("Style"), OWN_ATTR_STYLE, &::com::sun::star::style::XStyle::static_type(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0}, 83 { MAP_CHAR_LEN(UNO_NAME_TEXT_WRITINGMODE), SDRATTR_TEXTDIRECTION, &::getCppuType( (::com::sun::star::text::WritingMode*) 0 ), 0, 0}, 84 { MAP_CHAR_LEN(UNO_NAME_TEXT_HORZADJUST), SDRATTR_TEXT_HORZADJUST, &::getCppuType((const ::com::sun::star::drawing::TextHorizontalAdjust*)0), 0, 0}, \ 85 { MAP_CHAR_LEN(UNO_NAME_TEXT_LEFTDIST), SDRATTR_TEXT_LEFTDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \ 86 { MAP_CHAR_LEN(UNO_NAME_TEXT_LOWERDIST), SDRATTR_TEXT_LOWERDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \ 87 { MAP_CHAR_LEN(UNO_NAME_TEXT_RIGHTDIST), SDRATTR_TEXT_RIGHTDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \ 88 { MAP_CHAR_LEN(UNO_NAME_TEXT_UPPERDIST), SDRATTR_TEXT_UPPERDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \ 89 { MAP_CHAR_LEN(UNO_NAME_TEXT_VERTADJUST), SDRATTR_TEXT_VERTADJUST, &::getCppuType((const ::com::sun::star::drawing::TextVerticalAdjust*)0), 0, 0},\ 90 { MAP_CHAR_LEN(UNO_NAME_TEXT_WORDWRAP), SDRATTR_TEXT_WORDWRAP, &::getBooleanCppuType(), 0, 0}, \ 91 92 { MAP_CHAR_LEN("TableBorder"), OWN_ATTR_TABLEBORDER, &::getCppuType((const TableBorder*)0), 0, 0 }, \ 93 { MAP_CHAR_LEN("TopBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, TOP_BORDER }, \ 94 { MAP_CHAR_LEN("BottomBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, BOTTOM_BORDER }, \ 95 { MAP_CHAR_LEN("LeftBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, LEFT_BORDER }, \ 96 { MAP_CHAR_LEN("RightBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, RIGHT_BORDER }, \ 97 98 SVX_UNOEDIT_OUTLINER_PROPERTIES, 99 SVX_UNOEDIT_CHAR_PROPERTIES, 100 SVX_UNOEDIT_PARA_PROPERTIES, 101 {0,0,0,0,0,0} 102 }; 103 104 static SvxItemPropertySet aSvxCellPropertySet( aSvxCellPropertyMap, SdrObject::GetGlobalDrawObjectItemPool() ); 105 return &aSvxCellPropertySet; 106 } 107 108 namespace sdr 109 { 110 namespace properties 111 { 112 class CellProperties : public TextProperties 113 { 114 protected: 115 // create a new itemset 116 SfxItemSet& CreateObjectSpecificItemSet(SfxItemPool& rPool); 117 118 public: 119 // basic constructor 120 CellProperties(SdrObject& rObj, sdr::table::Cell* pCell ); 121 122 // constructor for copying, but using new object 123 CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell); 124 125 // destructor 126 ~CellProperties(); 127 128 // Clone() operator, normally just calls the local copy constructor 129 BaseProperties& Clone(SdrObject& rObj) const; 130 131 void ForceDefaultAttributes(); 132 133 void ItemSetChanged(const SfxItemSet& rSet); 134 135 void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem); 136 137 void SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr); 138 139 sdr::table::CellRef mxCell; 140 }; 141 142 // create a new itemset 143 SfxItemSet& CellProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool) 144 { 145 return *(new SfxItemSet(rPool, 146 147 // range from SdrAttrObj 148 SDRATTR_START, SDRATTR_SHADOW_LAST, 149 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST, 150 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 151 152 // range for SdrTableObj 153 SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST, 154 155 // range from SdrTextObj 156 EE_ITEMS_START, EE_ITEMS_END, 157 158 // end 159 0, 0)); 160 } 161 162 CellProperties::CellProperties(SdrObject& rObj, sdr::table::Cell* pCell) 163 : TextProperties(rObj) 164 , mxCell(pCell) 165 { 166 } 167 168 CellProperties::CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell) 169 : TextProperties(rProps, rObj) 170 , mxCell( pCell ) 171 { 172 } 173 174 CellProperties::~CellProperties() 175 { 176 } 177 178 BaseProperties& CellProperties::Clone(SdrObject& rObj) const 179 { 180 DBG_ERROR("CellProperties::Clone(), does not work yet!"); 181 return *(new CellProperties(*this, rObj,0)); 182 } 183 184 void CellProperties::ForceDefaultAttributes() 185 { 186 } 187 188 void CellProperties::ItemSetChanged(const SfxItemSet& rSet ) 189 { 190 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject(); 191 192 if( mxCell.is() ) 193 { 194 OutlinerParaObject* pParaObj = mxCell->GetEditOutlinerParaObject(); 195 196 bool bOwnParaObj = pParaObj != 0; 197 198 if( pParaObj == 0 ) 199 pParaObj = mxCell->GetOutlinerParaObject(); 200 201 if(pParaObj) 202 { 203 // handle outliner attributes 204 Outliner* pOutliner = 0; 205 206 if(mxCell->IsTextEditActive()) 207 { 208 pOutliner = rObj.GetTextEditOutliner(); 209 } 210 else 211 { 212 pOutliner = &rObj.ImpGetDrawOutliner(); 213 pOutliner->SetText(*pParaObj); 214 } 215 216 sal_uInt32 nParaCount(pOutliner->GetParagraphCount()); 217 218 for(sal_uInt16 nPara = 0; nPara < nParaCount; nPara++) 219 { 220 SfxItemSet aSet(pOutliner->GetParaAttribs(nPara)); 221 aSet.Put(rSet); 222 pOutliner->SetParaAttribs(nPara, aSet); 223 } 224 225 if(!mxCell->IsTextEditActive()) 226 { 227 if(nParaCount) 228 { 229 // force ItemSet 230 GetObjectItemSet(); 231 232 SfxItemSet aNewSet(pOutliner->GetParaAttribs(0L)); 233 mpItemSet->Put(aNewSet); 234 } 235 236 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, (sal_uInt16)nParaCount); 237 pOutliner->Clear(); 238 239 mxCell->SetOutlinerParaObject(pTemp); 240 } 241 242 if( bOwnParaObj ) 243 delete pParaObj; 244 } 245 } 246 247 // call parent 248 AttributeProperties::ItemSetChanged(rSet); 249 250 if( mxCell.is() ) 251 mxCell->notifyModified(); 252 } 253 254 void CellProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem) 255 { 256 if(pNewItem && (SDRATTR_TEXTDIRECTION == nWhich)) 257 { 258 sal_Bool bVertical(com::sun::star::text::WritingMode_TB_RL == ((SvxWritingModeItem*)pNewItem)->GetValue()); 259 260 sdr::table::SdrTableObj& rObj = (sdr::table::SdrTableObj&)GetSdrObject(); 261 if( rObj.IsVerticalWriting() != bVertical ) 262 rObj.SetVerticalWriting(bVertical); 263 } 264 265 // call parent 266 AttributeProperties::ItemChange( nWhich, pNewItem ); 267 } 268 269 void CellProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr) 270 { 271 TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr ); 272 } 273 } // end of namespace properties 274 } // end of namespace sdr 275 276 namespace sdr { namespace table { 277 278 // ----------------------------------------------------------------------------- 279 // Cell 280 // ----------------------------------------------------------------------------- 281 282 rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject ) 283 { 284 rtl::Reference< Cell > xCell( new Cell( rTableObj, pOutlinerParaObject ) ); 285 if( xCell->mxTable.is() ) 286 { 287 Reference< XEventListener > xListener( xCell.get() ); 288 xCell->mxTable->addEventListener( xListener ); 289 } 290 return xCell; 291 } 292 293 // ----------------------------------------------------------------------------- 294 295 Cell::Cell( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject ) throw() 296 : SdrText( rTableObj, pOutlinerParaObject ) 297 , SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() ) 298 , mpPropSet( ImplGetSvxCellPropertySet() ) 299 , mpProperties( new sdr::properties::CellProperties( rTableObj, this ) ) 300 , mnCellContentType( CellContentType_EMPTY ) 301 , mfValue( 0.0 ) 302 , mnError( 0 ) 303 , mbMerged( sal_False ) 304 , mnRowSpan( 1 ) 305 , mnColSpan( 1 ) 306 , mxTable( rTableObj.getTable() ) 307 { 308 if( rTableObj.GetModel() ) 309 SetModel( rTableObj.GetModel() ); 310 } 311 312 // ----------------------------------------------------------------------------- 313 314 Cell::~Cell() throw() 315 { 316 dispose(); 317 } 318 319 // ----------------------------------------------------------------------------- 320 321 void Cell::dispose() 322 { 323 if( mxTable.is() ) 324 { 325 try 326 { 327 Reference< XEventListener > xThis( this ); 328 mxTable->removeEventListener( xThis ); 329 } 330 catch( Exception& ) 331 { 332 DBG_ERROR("Cell::dispose(), exception caught!"); 333 } 334 mxTable.clear(); 335 } 336 337 if( mpProperties ) 338 { 339 delete mpProperties; 340 mpProperties = 0; 341 } 342 SetOutlinerParaObject( 0 ); 343 } 344 345 // ----------------------------------------------------------------------------- 346 347 void Cell::SetModel(SdrModel* pNewModel) 348 { 349 SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( GetEditSource() ); 350 if( (GetModel() != pNewModel) || ( pNewModel && !pTextEditSource) ) 351 { 352 if( mpProperties ) 353 { 354 SfxItemPool* pItemPool = mpProperties->GetObjectItemSet().GetPool(); 355 356 // test for correct pool in ItemSet; move to new pool if necessary 357 if( pNewModel && pItemPool && pItemPool != &pNewModel->GetItemPool()) 358 mpProperties->MoveToItemPool(pItemPool, &pNewModel->GetItemPool(), pNewModel); 359 } 360 361 if( pTextEditSource ) 362 { 363 pTextEditSource->ChangeModel( pNewModel ); 364 } 365 else 366 { 367 SetEditSource( new SvxTextEditSource( &GetObject(), this, static_cast< XWeak * >( this ) ) ); 368 } 369 370 SetStyleSheet( 0, sal_True ); 371 SdrText::SetModel( pNewModel ); 372 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT ); 373 } 374 } 375 376 // ----------------------------------------------------------------------------- 377 378 void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan ) 379 { 380 if( (mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || (mbMerged != sal_False) ) 381 { 382 mnColSpan = nColumnSpan; 383 mnRowSpan = nRowSpan; 384 mbMerged = sal_False; 385 notifyModified(); 386 } 387 } 388 389 // ----------------------------------------------------------------------------- 390 391 void Cell::mergeContent( const CellRef& xSourceCell ) 392 { 393 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); 394 395 if( xSourceCell->hasText() ) 396 { 397 SdrOutliner& rOutliner=rTableObj.ImpGetDrawOutliner(); 398 rOutliner.SetUpdateMode(sal_True); 399 400 if( hasText() ) 401 { 402 rOutliner.SetText(*GetOutlinerParaObject()); 403 rOutliner.AddText(*xSourceCell->GetOutlinerParaObject()); 404 } 405 else 406 { 407 rOutliner.SetText(*xSourceCell->GetOutlinerParaObject()); 408 } 409 410 SetOutlinerParaObject( rOutliner.CreateParaObject() ); 411 rOutliner.Clear(); 412 xSourceCell->SetOutlinerParaObject(rOutliner.CreateParaObject()); 413 rOutliner.Clear(); 414 SetStyleSheet( GetStyleSheet(), sal_True ); 415 } 416 } 417 418 // ----------------------------------------------------------------------------- 419 420 void Cell::cloneFrom( const CellRef& xCell ) 421 { 422 if( xCell.is() ) 423 { 424 replaceContentAndFormating( xCell ); 425 426 mnCellContentType = xCell->mnCellContentType; 427 428 msFormula = xCell->msFormula; 429 mfValue = xCell->mfValue; 430 mnError = xCell->mnError; 431 432 mbMerged = xCell->mbMerged; 433 mnRowSpan = xCell->mnRowSpan; 434 mnColSpan = xCell->mnColSpan; 435 436 } 437 notifyModified(); 438 } 439 440 void Cell::replaceContentAndFormating( const CellRef& xSourceCell ) 441 { 442 if( xSourceCell.is() && mpProperties ) 443 { 444 mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() ); 445 SetOutlinerParaObject( new OutlinerParaObject(*xSourceCell->GetOutlinerParaObject()) ); 446 447 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); 448 SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() ); 449 450 if(rSourceTableObj.GetModel() != rTableObj.GetModel()) 451 { 452 SetStyleSheet( 0, sal_True ); 453 } 454 } 455 } 456 457 // ----------------------------------------------------------------------------- 458 459 void Cell::setMerged() 460 { 461 if( !mbMerged ) 462 { 463 mbMerged = sal_True; 464 notifyModified(); 465 } 466 } 467 468 // ----------------------------------------------------------------------------- 469 470 void Cell::notifyModified() 471 { 472 if( mxTable.is() ) 473 mxTable->setModified( sal_True ); 474 } 475 476 // ----------------------------------------------------------------------------- 477 // SdrTextShape proxy 478 // ----------------------------------------------------------------------------- 479 480 bool Cell::IsTextEditActive() 481 { 482 bool isActive = false; 483 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); 484 if(rTableObj.getActiveCell().get() == this ) 485 { 486 OutlinerParaObject* pParaObj = rTableObj.GetEditOutlinerParaObject(); 487 if( pParaObj != 0 ) 488 { 489 isActive = true; 490 delete pParaObj; 491 } 492 } 493 return isActive; 494 } 495 496 // ----------------------------------------------------------------------------- 497 498 bool Cell::hasText() const 499 { 500 OutlinerParaObject* pParaObj = GetOutlinerParaObject(); 501 if( pParaObj ) 502 { 503 const EditTextObject& rTextObj = pParaObj->GetTextObject(); 504 if( rTextObj.GetParagraphCount() >= 1 ) 505 { 506 if( rTextObj.GetParagraphCount() == 1 ) 507 { 508 if( rTextObj.GetText(0).Len() == 0 ) 509 return false; 510 } 511 return true; 512 } 513 } 514 515 return false; 516 } 517 518 // ----------------------------------------------------------------------------- 519 520 OutlinerParaObject* Cell::GetEditOutlinerParaObject() const 521 { 522 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); 523 if( rTableObj.getActiveCell().get() == this ) 524 return rTableObj.GetEditOutlinerParaObject(); 525 return 0; 526 } 527 528 // ----------------------------------------------------------------------------- 529 530 void Cell::SetStyleSheet( SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr ) 531 { 532 // only allow cell styles for cells 533 if( pStyleSheet && pStyleSheet->GetFamily() != SFX_STYLE_FAMILY_FRAME ) 534 return; 535 536 if( mpProperties && (mpProperties->GetStyleSheet() != pStyleSheet) ) 537 { 538 mpProperties->SetStyleSheet( pStyleSheet, bDontRemoveHardAttr ); 539 } 540 } 541 542 // ----------------------------------------------------------------------------- 543 544 const SfxItemSet& Cell::GetObjectItemSet() 545 { 546 if( mpProperties ) 547 { 548 return mpProperties->GetObjectItemSet(); 549 } 550 else 551 { 552 DBG_ERROR("Cell::GetObjectItemSet(), called without properties!"); 553 return GetObject().GetObjectItemSet(); 554 } 555 } 556 557 void Cell::SetObjectItem(const SfxPoolItem& rItem) 558 { 559 if( mpProperties ) 560 { 561 mpProperties->SetObjectItem( rItem ); 562 notifyModified(); 563 } 564 } 565 566 void Cell::SetMergedItem(const SfxPoolItem& rItem) 567 { 568 SetObjectItem(rItem); 569 } 570 571 SfxStyleSheet* Cell::GetStyleSheet() const 572 { 573 if( mpProperties ) 574 return mpProperties->GetStyleSheet(); 575 else 576 return 0; 577 } 578 579 // ----------------------------------------------------------------------------- 580 581 SfxStyleSheetPool* Cell::GetStyleSheetPool() const 582 { 583 if( mpProperties && mpProperties->GetStyleSheet() ) 584 return dynamic_cast< SfxStyleSheetPool* >( &mpProperties->GetStyleSheet()->GetPool() ); 585 else 586 return 0; 587 } 588 589 // ----------------------------------------------------------------------------- 590 591 const Rectangle& Cell::GetCurrentBoundRect() const 592 { 593 return maCellRect; 594 } 595 596 // ----------------------------------------------------------------------------- 597 598 void Cell::TakeTextAnchorRect(Rectangle& rAnchorRect) const 599 { 600 rAnchorRect.nLeft = maCellRect.nLeft + GetTextLeftDistance(); 601 rAnchorRect.nRight = maCellRect.nRight - GetTextRightDistance(); 602 rAnchorRect.nTop = maCellRect.nTop + GetTextUpperDistance(); 603 rAnchorRect.nBottom = maCellRect.nBottom - GetTextLowerDistance(); 604 } 605 606 // ----------------------------------------------------------------------------- 607 608 const SfxItemSet& Cell::GetItemSet() const 609 { 610 return mpProperties->GetObjectItemSet(); 611 } 612 613 // ----------------------------------------------------------------------------- 614 615 void Cell::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, sal_Bool bClearAllItems) 616 { 617 if( mpProperties ) 618 { 619 mpProperties->SetMergedItemSetAndBroadcast(rSet, bClearAllItems); 620 notifyModified(); 621 } 622 } 623 624 // ----------------------------------------------------------------------------- 625 626 sal_Int32 Cell::getMinimumWidth() 627 { 628 return GetTextLeftDistance() + GetTextRightDistance() + 100; 629 } 630 631 // ----------------------------------------------------------------------------- 632 633 sal_Int32 Cell::getMinimumHeight() 634 { 635 if( !mpProperties ) 636 return 0; 637 638 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); 639 sal_Int32 nMinimumHeight = 0; 640 641 Rectangle aTextRect; 642 TakeTextAnchorRect( aTextRect ); 643 Size aSize( aTextRect.GetSize() ); 644 aSize.Height()=0x0FFFFFFF; 645 646 SdrOutliner* pEditOutliner = rTableObj.GetCellTextEditOutliner( *this ); 647 if(pEditOutliner) 648 { 649 pEditOutliner->SetMaxAutoPaperSize(aSize); 650 nMinimumHeight = pEditOutliner->GetTextHeight()+1; 651 } 652 else /*if ( hasText() )*/ 653 { 654 Outliner& rOutliner=rTableObj.ImpGetDrawOutliner(); 655 rOutliner.SetPaperSize(aSize); 656 rOutliner.SetUpdateMode(sal_True); 657 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT ); 658 659 if( GetOutlinerParaObject() ) 660 { 661 rOutliner.SetText(*GetOutlinerParaObject()); 662 } 663 nMinimumHeight=rOutliner.GetTextHeight()+1; 664 rOutliner.Clear(); 665 } 666 667 nMinimumHeight += GetTextUpperDistance() + GetTextLowerDistance(); 668 return nMinimumHeight; 669 } 670 671 // ----------------------------------------------------------------------------- 672 673 long Cell::GetTextLeftDistance() const 674 { 675 return ((SdrTextLeftDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LEFTDIST))).GetValue(); 676 } 677 678 // ----------------------------------------------------------------------------- 679 680 long Cell::GetTextRightDistance() const 681 { 682 return ((SdrTextRightDistItem&)(GetItemSet().Get(SDRATTR_TEXT_RIGHTDIST))).GetValue(); 683 } 684 685 // ----------------------------------------------------------------------------- 686 687 long Cell::GetTextUpperDistance() const 688 { 689 return ((SdrTextUpperDistItem&)(GetItemSet().Get(SDRATTR_TEXT_UPPERDIST))).GetValue(); 690 } 691 692 // ----------------------------------------------------------------------------- 693 694 long Cell::GetTextLowerDistance() const 695 { 696 return ((SdrTextLowerDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LOWERDIST))).GetValue(); 697 } 698 699 // ----------------------------------------------------------------------------- 700 701 SdrTextVertAdjust Cell::GetTextVerticalAdjust() const 702 { 703 return ((SdrTextVertAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_VERTADJUST))).GetValue(); 704 } 705 706 // ----------------------------------------------------------------------------- 707 708 SdrTextHorzAdjust Cell::GetTextHorizontalAdjust() const 709 { 710 return ((SdrTextHorzAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_HORZADJUST))).GetValue(); 711 } 712 713 // ----------------------------------------------------------------------------- 714 715 void Cell::SetOutlinerParaObject( OutlinerParaObject* pTextObject ) 716 { 717 SdrText::SetOutlinerParaObject( pTextObject ); 718 maSelection.nStartPara = 0xffff; 719 720 if( pTextObject == 0 ) 721 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT ); 722 } 723 724 // ----------------------------------------------------------------------------- 725 726 void Cell::AddUndo() 727 { 728 SdrObject& rObj = GetObject(); 729 if( rObj.IsInserted() && GetModel() && GetModel()->IsUndoEnabled() ) 730 { 731 CellRef xCell( this ); 732 GetModel()->AddUndo( new CellUndo( &rObj, xCell ) ); 733 } 734 } 735 736 // ----------------------------------------------------------------------------- 737 738 sdr::properties::TextProperties* Cell::CloneProperties( sdr::properties::TextProperties* pProperties, SdrObject& rNewObj, Cell& rNewCell ) 739 { 740 if( pProperties ) 741 return new sdr::properties::CellProperties( *static_cast<sdr::properties::CellProperties*>(pProperties), rNewObj, &rNewCell ); 742 else 743 return 0; 744 } 745 746 // ----------------------------------------------------------------------------- 747 748 sdr::properties::TextProperties* Cell::CloneProperties( SdrObject& rNewObj, Cell& rNewCell ) 749 { 750 return CloneProperties(mpProperties,rNewObj,rNewCell); 751 } 752 753 // ----------------------------------------------------------------------------- 754 // XInterface 755 // ----------------------------------------------------------------------------- 756 757 Any SAL_CALL Cell::queryInterface( const Type & rType ) throw(RuntimeException) 758 { 759 if( rType == XMergeableCell::static_type() ) 760 return Any( Reference< XMergeableCell >( this ) ); 761 762 if( rType == XCell::static_type() ) 763 return Any( Reference< XCell >( this ) ); 764 765 if( rType == XLayoutConstrains::static_type() ) 766 return Any( Reference< XLayoutConstrains >( this ) ); 767 768 if( rType == XEventListener::static_type() ) 769 return Any( Reference< XEventListener >( this ) ); 770 771 Any aRet( SvxUnoTextBase::queryAggregation( rType ) ); 772 if( aRet.hasValue() ) 773 return aRet; 774 775 return ::cppu::OWeakObject::queryInterface( rType ); 776 } 777 778 // ----------------------------------------------------------------------------- 779 780 void SAL_CALL Cell::acquire() throw () 781 { 782 ::cppu::OWeakObject::acquire(); 783 } 784 785 // ----------------------------------------------------------------------------- 786 787 void SAL_CALL Cell::release() throw () 788 { 789 ::cppu::OWeakObject::release(); 790 } 791 792 // ----------------------------------------------------------------------------- 793 // XTypeProvider 794 // ----------------------------------------------------------------------------- 795 796 Sequence< Type > SAL_CALL Cell::getTypes( ) throw (RuntimeException) 797 { 798 Sequence< Type > aTypes( SvxUnoTextBase::getTypes() ); 799 800 sal_Int32 nLen = aTypes.getLength(); 801 aTypes.realloc(nLen + 2); 802 aTypes[nLen++] = XMergeableCell::static_type(); 803 aTypes[nLen++] = XLayoutConstrains::static_type(); 804 805 return aTypes; 806 } 807 808 // ----------------------------------------------------------------------------- 809 810 Sequence< sal_Int8 > SAL_CALL Cell::getImplementationId( ) throw (RuntimeException) 811 { 812 static ::cppu::OImplementationId* pId = 0; 813 if (! pId) 814 { 815 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 816 if (! pId) 817 { 818 static ::cppu::OImplementationId aId; 819 pId = &aId; 820 } 821 } 822 return pId->getImplementationId(); 823 } 824 825 // ----------------------------------------------------------------------------- 826 // XServiceInfo 827 // ----------------------------------------------------------------------------- 828 829 OUString SAL_CALL Cell::getImplementationName( ) throw (RuntimeException) 830 { 831 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.table.Cell" ) ); 832 } 833 834 // ----------------------------------------------------------------------------- 835 836 sal_Bool SAL_CALL Cell::supportsService( const OUString& ServiceName ) throw (RuntimeException) 837 { 838 if( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.table.cell" ) ) == 0 ) 839 return sal_True; 840 841 if( ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.cell" ) ) == 0 ) 842 return sal_True; 843 844 return SvxUnoTextBase::supportsService( ServiceName ); 845 } 846 847 // ----------------------------------------------------------------------------- 848 849 Sequence< OUString > SAL_CALL Cell::getSupportedServiceNames( ) throw (RuntimeException) 850 { 851 Sequence< OUString > aSeq( SvxUnoTextBase::getSupportedServiceNames() ); 852 sal_Int32 nIndex = aSeq.getLength(); 853 aSeq.realloc( nIndex + 2 ); 854 aSeq[nIndex++] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.cell" ) ); 855 aSeq[nIndex++] = OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.cell" ) ); 856 return aSeq; 857 } 858 859 // ----------------------------------------------------------------------------- 860 // XLayoutConstrains 861 // ----------------------------------------------------------------------------- 862 863 ::com::sun::star::awt::Size SAL_CALL Cell::getMinimumSize( ) throw (RuntimeException) 864 { 865 return ::com::sun::star::awt::Size( getMinimumWidth(), getMinimumHeight() ); 866 } 867 868 // ----------------------------------------------------------------------------- 869 870 ::com::sun::star::awt::Size SAL_CALL Cell::getPreferredSize( ) throw (RuntimeException) 871 { 872 return getMinimumSize(); 873 } 874 875 // ----------------------------------------------------------------------------- 876 877 ::com::sun::star::awt::Size SAL_CALL Cell::calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (RuntimeException) 878 { 879 return aNewSize; 880 } 881 882 // ----------------------------------------------------------------------------- 883 // XMergeableCell 884 // ----------------------------------------------------------------------------- 885 886 sal_Int32 SAL_CALL Cell::getRowSpan() throw (RuntimeException) 887 { 888 return mnRowSpan; 889 } 890 891 // ----------------------------------------------------------------------------- 892 893 sal_Int32 SAL_CALL Cell::getColumnSpan() throw (RuntimeException) 894 { 895 return mnColSpan; 896 } 897 898 // ----------------------------------------------------------------------------- 899 900 sal_Bool SAL_CALL Cell::isMerged() throw (RuntimeException) 901 { 902 return mbMerged; 903 } 904 905 // ----------------------------------------------------------------------------- 906 // XCell 907 // ----------------------------------------------------------------------------- 908 909 OUString SAL_CALL Cell::getFormula( ) throw (RuntimeException) 910 { 911 return msFormula; 912 } 913 914 // ----------------------------------------------------------------------------- 915 916 void SAL_CALL Cell::setFormula( const OUString& aFormula ) throw (RuntimeException) 917 { 918 if( msFormula != aFormula ) 919 { 920 msFormula = aFormula; 921 } 922 } 923 924 // ----------------------------------------------------------------------------- 925 926 double SAL_CALL Cell::getValue( ) throw (RuntimeException) 927 { 928 return mfValue; 929 } 930 931 // ----------------------------------------------------------------------------- 932 933 void SAL_CALL Cell::setValue( double nValue ) throw (RuntimeException) 934 { 935 if( mfValue == nValue ) 936 { 937 mfValue = nValue; 938 mnCellContentType = CellContentType_VALUE; 939 } 940 } 941 942 // ----------------------------------------------------------------------------- 943 944 CellContentType SAL_CALL Cell::getType() throw (RuntimeException) 945 { 946 return mnCellContentType; 947 } 948 949 // ----------------------------------------------------------------------------- 950 951 sal_Int32 SAL_CALL Cell::getError( ) throw (RuntimeException) 952 { 953 return mnError; 954 } 955 956 // ----------------------------------------------------------------------------- 957 // XPropertySet 958 // ----------------------------------------------------------------------------- 959 960 Any Cell::GetAnyForItem( SfxItemSet& aSet, const SfxItemPropertySimpleEntry* pMap ) 961 { 962 Any aAny( SvxItemPropertySet_getPropertyValue( *mpPropSet, pMap, aSet ) ); 963 964 if( *pMap->pType != aAny.getValueType() ) 965 { 966 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here 967 if( ( *pMap->pType == ::getCppuType((const sal_Int16*)0)) && aAny.getValueType() == ::getCppuType((const sal_Int32*)0) ) 968 { 969 sal_Int32 nValue = 0; 970 aAny >>= nValue; 971 aAny <<= (sal_Int16)nValue; 972 } 973 else 974 { 975 DBG_ERROR("GetAnyForItem() Returnvalue has wrong Type!" ); 976 } 977 } 978 979 return aAny; 980 } 981 982 Reference< XPropertySetInfo > SAL_CALL Cell::getPropertySetInfo() throw(RuntimeException) 983 { 984 return mpPropSet->getPropertySetInfo(); 985 } 986 987 // ----------------------------------------------------------------------------- 988 989 void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 990 { 991 OGuard aGuard( Application::GetSolarMutex() ); 992 993 if( (mpProperties == 0) || (GetModel() == 0) ) 994 throw DisposedException(); 995 996 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName); 997 if( pMap ) 998 { 999 if( (pMap->nFlags & PropertyAttribute::READONLY ) != 0 ) 1000 throw PropertyVetoException(); 1001 1002 switch( pMap->nWID ) 1003 { 1004 case OWN_ATTR_STYLE: 1005 { 1006 Reference< XStyle > xStyle; 1007 if( !( rValue >>= xStyle ) ) 1008 throw IllegalArgumentException(); 1009 1010 SfxUnoStyleSheet* pStyle = SfxUnoStyleSheet::getUnoStyleSheet(xStyle); 1011 SetStyleSheet( pStyle, sal_True ); 1012 return; 1013 } 1014 case OWN_ATTR_TABLEBORDER: 1015 { 1016 if(rValue.getValueType() != ::getCppuType((const TableBorder*)0) ) 1017 break; 1018 1019 const TableBorder* pBorder = (const TableBorder* )rValue.getValue(); 1020 if( pBorder == NULL ) 1021 break; 1022 1023 SvxBoxItem aBox( SDRATTR_TABLE_BORDER ); 1024 SvxBoxInfoItem aBoxInfo( SDRATTR_TABLE_BORDER_INNER ); 1025 SvxBorderLine aLine; 1026 1027 sal_Bool bSet = SvxBoxItem::LineToSvxLine(pBorder->TopLine, aLine, false); 1028 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_TOP); 1029 aBoxInfo.SetValid(VALID_TOP, pBorder->IsTopLineValid); 1030 1031 bSet = SvxBoxItem::LineToSvxLine(pBorder->BottomLine, aLine, false); 1032 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_BOTTOM); 1033 aBoxInfo.SetValid(VALID_BOTTOM, pBorder->IsBottomLineValid); 1034 1035 bSet = SvxBoxItem::LineToSvxLine(pBorder->LeftLine, aLine, false); 1036 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_LEFT); 1037 aBoxInfo.SetValid(VALID_LEFT, pBorder->IsLeftLineValid); 1038 1039 bSet = SvxBoxItem::LineToSvxLine(pBorder->RightLine, aLine, false); 1040 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_RIGHT); 1041 aBoxInfo.SetValid(VALID_RIGHT, pBorder->IsRightLineValid); 1042 1043 bSet = SvxBoxItem::LineToSvxLine(pBorder->HorizontalLine, aLine, false); 1044 aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_HORI); 1045 aBoxInfo.SetValid(VALID_HORI, pBorder->IsHorizontalLineValid); 1046 1047 bSet = SvxBoxItem::LineToSvxLine(pBorder->VerticalLine, aLine, false); 1048 aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_VERT); 1049 aBoxInfo.SetValid(VALID_VERT, pBorder->IsVerticalLineValid); 1050 1051 aBox.SetDistance(pBorder->Distance, false); 1052 aBoxInfo.SetValid(VALID_DISTANCE, pBorder->IsDistanceValid); 1053 1054 mpProperties->SetObjectItem(aBox); 1055 mpProperties->SetObjectItem(aBoxInfo); 1056 return; 1057 } 1058 case OWN_ATTR_FILLBMP_MODE: 1059 { 1060 BitmapMode eMode; 1061 if(!(rValue >>= eMode) ) 1062 { 1063 sal_Int32 nMode = 0; 1064 if(!(rValue >>= nMode)) 1065 throw IllegalArgumentException(); 1066 1067 eMode = (BitmapMode)nMode; 1068 } 1069 1070 mpProperties->SetObjectItem( XFillBmpStretchItem( eMode == BitmapMode_STRETCH ) ); 1071 mpProperties->SetObjectItem( XFillBmpTileItem( eMode == BitmapMode_REPEAT ) ); 1072 return; 1073 } 1074 default: 1075 { 1076 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID); 1077 aSet.Put(mpProperties->GetItem(pMap->nWID)); 1078 1079 bool bSpecial = false; 1080 1081 switch( pMap->nWID ) 1082 { 1083 case XATTR_FILLBITMAP: 1084 case XATTR_FILLGRADIENT: 1085 case XATTR_FILLHATCH: 1086 case XATTR_FILLFLOATTRANSPARENCE: 1087 case XATTR_LINEEND: 1088 case XATTR_LINESTART: 1089 case XATTR_LINEDASH: 1090 { 1091 if( pMap->nMemberId == MID_NAME ) 1092 { 1093 OUString aApiName; 1094 if( rValue >>= aApiName ) 1095 { 1096 if( SvxShape::SetFillAttribute( pMap->nWID, aApiName, aSet, GetModel() ) ) 1097 bSpecial = true; 1098 } 1099 } 1100 } 1101 break; 1102 } 1103 1104 if( !bSpecial ) 1105 { 1106 1107 if( !SvxUnoTextRangeBase::SetPropertyValueHelper( aSet, pMap, rValue, aSet )) 1108 { 1109 if( aSet.GetItemState( pMap->nWID ) != SFX_ITEM_SET ) 1110 { 1111 // Default aus ItemPool holen 1112 if(GetModel()->GetItemPool().IsWhich(pMap->nWID)) 1113 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); 1114 } 1115 1116 if( aSet.GetItemState( pMap->nWID ) == SFX_ITEM_SET ) 1117 { 1118 SvxItemPropertySet_setPropertyValue( *mpPropSet, pMap, rValue, aSet ); 1119 } 1120 } 1121 } 1122 1123 GetModel()->SetChanged(); 1124 mpProperties->SetMergedItemSetAndBroadcast( aSet ); 1125 return; 1126 } 1127 } 1128 } 1129 throw UnknownPropertyException(); 1130 } 1131 1132 // ----------------------------------------------------------------------------- 1133 1134 Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1135 { 1136 OGuard aGuard( Application::GetSolarMutex() ); 1137 1138 if( (mpProperties == 0) || (GetModel() == 0) ) 1139 throw DisposedException(); 1140 1141 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); 1142 if( pMap ) 1143 { 1144 switch( pMap->nWID ) 1145 { 1146 /* 1147 case OWN_ATTR_HASLEVELS: 1148 { 1149 return Any( hasLevels() ); 1150 } 1151 */ 1152 case OWN_ATTR_STYLE: 1153 { 1154 return Any( Reference< XStyle >( dynamic_cast< SfxUnoStyleSheet* >( GetStyleSheet() ) ) ); 1155 } 1156 case OWN_ATTR_TABLEBORDER: 1157 { 1158 const SvxBoxInfoItem& rBoxInfoItem = static_cast<const SvxBoxInfoItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER_INNER)); 1159 const SvxBoxItem& rBox = static_cast<const SvxBoxItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER)); 1160 1161 TableBorder aTableBorder; 1162 aTableBorder.TopLine = SvxBoxItem::SvxLineToLine(rBox.GetTop(), false); 1163 aTableBorder.IsTopLineValid = rBoxInfoItem.IsValid(VALID_TOP); 1164 aTableBorder.BottomLine = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), false); 1165 aTableBorder.IsBottomLineValid = rBoxInfoItem.IsValid(VALID_BOTTOM); 1166 aTableBorder.LeftLine = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), false); 1167 aTableBorder.IsLeftLineValid = rBoxInfoItem.IsValid(VALID_LEFT); 1168 aTableBorder.RightLine = SvxBoxItem::SvxLineToLine(rBox.GetRight(), false); 1169 aTableBorder.IsRightLineValid = rBoxInfoItem.IsValid(VALID_RIGHT ); 1170 aTableBorder.HorizontalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), false); 1171 aTableBorder.IsHorizontalLineValid = rBoxInfoItem.IsValid(VALID_HORI); 1172 aTableBorder.VerticalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), false); 1173 aTableBorder.IsVerticalLineValid = rBoxInfoItem.IsValid(VALID_VERT); 1174 aTableBorder.Distance = rBox.GetDistance(); 1175 aTableBorder.IsDistanceValid = rBoxInfoItem.IsValid(VALID_DISTANCE); 1176 1177 return Any( aTableBorder ); 1178 } 1179 case OWN_ATTR_FILLBMP_MODE: 1180 { 1181 const XFillBmpStretchItem& rStretchItem = static_cast<const XFillBmpStretchItem&>(mpProperties->GetItem(XATTR_FILLBMP_STRETCH)); 1182 const XFillBmpTileItem& rTileItem = static_cast<const XFillBmpTileItem&>(mpProperties->GetItem(XATTR_FILLBMP_TILE)); 1183 if( rTileItem.GetValue() ) 1184 { 1185 return Any( BitmapMode_REPEAT ); 1186 } 1187 else if( rStretchItem.GetValue() ) 1188 { 1189 return Any( BitmapMode_STRETCH ); 1190 } 1191 else 1192 { 1193 return Any( BitmapMode_NO_REPEAT ); 1194 } 1195 } 1196 default: 1197 { 1198 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID); 1199 aSet.Put(mpProperties->GetItem(pMap->nWID)); 1200 1201 Any aAny; 1202 if(!SvxUnoTextRangeBase::GetPropertyValueHelper( aSet, pMap, aAny )) 1203 { 1204 if(!aSet.Count()) 1205 { 1206 // Default aus ItemPool holen 1207 if(GetModel()->GetItemPool().IsWhich(pMap->nWID)) 1208 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); 1209 } 1210 1211 if( aSet.Count() ) 1212 aAny = GetAnyForItem( aSet, pMap ); 1213 } 1214 1215 return aAny; 1216 } 1217 } 1218 } 1219 throw UnknownPropertyException(); 1220 } 1221 1222 // ----------------------------------------------------------------------------- 1223 1224 void SAL_CALL Cell::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1225 { 1226 } 1227 1228 // ----------------------------------------------------------------------------- 1229 1230 void SAL_CALL Cell::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1231 { 1232 } 1233 1234 // ----------------------------------------------------------------------------- 1235 1236 void SAL_CALL Cell::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1237 { 1238 } 1239 1240 // ----------------------------------------------------------------------------- 1241 1242 void SAL_CALL Cell::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1243 { 1244 } 1245 1246 // ----------------------------------------------------------------------------- 1247 // XMultiPropertySet 1248 // ----------------------------------------------------------------------------- 1249 1250 void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 1251 { 1252 OGuard aSolarGuard( Application::GetSolarMutex() ); 1253 1254 if( (mpProperties == 0) || (GetModel() == 0) ) 1255 throw DisposedException(); 1256 1257 const sal_Int32 nCount = aPropertyNames.getLength(); 1258 1259 const OUString* pNames = aPropertyNames.getConstArray(); 1260 const Any* pValues = aValues.getConstArray(); 1261 1262 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pValues++ ) 1263 { 1264 try 1265 { 1266 setPropertyValue( *pNames, *pValues ); 1267 } 1268 catch( UnknownPropertyException& ) 1269 { 1270 DBG_ERROR("svx::Cell::setPropertyValues(), unknown property!" ); 1271 } 1272 catch( Exception& ) 1273 { 1274 DBG_ERROR("svx::Cell::setPropertyValues(), Exception caught!" ); 1275 } 1276 } 1277 } 1278 1279 // ----------------------------------------------------------------------------- 1280 1281 Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException) 1282 { 1283 OGuard aSolarGuard( Application::GetSolarMutex() ); 1284 1285 if( (mpProperties == 0) || (GetModel() == 0) ) 1286 throw DisposedException(); 1287 1288 const sal_Int32 nCount = aPropertyNames.getLength(); 1289 const OUString* pNames = aPropertyNames.getConstArray(); 1290 1291 Sequence< Any > aRet( nCount ); 1292 Any* pValue = aRet.getArray(); 1293 1294 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pValue++, pNames++ ) 1295 { 1296 try 1297 { 1298 *pValue = getPropertyValue( *pNames ); 1299 } 1300 catch( UnknownPropertyException& ) 1301 { 1302 DBG_ERROR("svx::Cell::setPropertyValues(), unknown property!" ); 1303 } 1304 catch( Exception& ) 1305 { 1306 DBG_ERROR( "svx::Cell::getPropertyValues(), Exception caught!" ); 1307 } 1308 } 1309 1310 return aRet; 1311 } 1312 1313 // ----------------------------------------------------------------------------- 1314 1315 void SAL_CALL Cell::addPropertiesChangeListener( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException) 1316 { 1317 } 1318 1319 // ----------------------------------------------------------------------------- 1320 1321 void SAL_CALL Cell::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException) 1322 { 1323 } 1324 1325 // ----------------------------------------------------------------------------- 1326 1327 void SAL_CALL Cell::firePropertiesChangeEvent( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException) 1328 { 1329 } 1330 1331 // ----------------------------------------------------------------------------- 1332 // XPropertyState 1333 // ----------------------------------------------------------------------------- 1334 1335 PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException) 1336 { 1337 OGuard aGuard( Application::GetSolarMutex() ); 1338 1339 if( (mpProperties == 0) || (GetModel() == 0) ) 1340 throw DisposedException(); 1341 1342 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); 1343 1344 if( pMap ) 1345 { 1346 PropertyState eState; 1347 switch( pMap->nWID ) 1348 { 1349 case OWN_ATTR_FILLBMP_MODE: 1350 { 1351 const SfxItemSet& rSet = mpProperties->GetMergedItemSet(); 1352 1353 const bool bStretch = rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET; 1354 const bool bTile = rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET; 1355 if( bStretch || bTile ) 1356 { 1357 eState = PropertyState_DIRECT_VALUE; 1358 } 1359 else 1360 { 1361 eState = PropertyState_DEFAULT_VALUE; 1362 } 1363 } 1364 /* 1365 case OWN_ATTR_HASLEVELS: 1366 { 1367 return PropertyState_DIRECT_VALUE; 1368 } 1369 */ 1370 case OWN_ATTR_STYLE: 1371 { 1372 return PropertyState_DIRECT_VALUE; 1373 } 1374 case OWN_ATTR_TABLEBORDER: 1375 { 1376 const SfxItemSet& rSet = mpProperties->GetMergedItemSet(); 1377 if( (rSet.GetItemState( SDRATTR_TABLE_BORDER_INNER, sal_False ) == SFX_ITEM_DEFAULT) && (rSet.GetItemState( SDRATTR_TABLE_BORDER, sal_False ) == SFX_ITEM_DEFAULT) ) 1378 return PropertyState_DEFAULT_VALUE; 1379 1380 return PropertyState_DIRECT_VALUE; 1381 } 1382 default: 1383 { 1384 const SfxItemSet& rSet = mpProperties->GetMergedItemSet(); 1385 1386 switch( rSet.GetItemState( pMap->nWID, sal_False ) ) 1387 { 1388 case SFX_ITEM_READONLY: 1389 case SFX_ITEM_SET: 1390 eState = PropertyState_DIRECT_VALUE; 1391 break; 1392 case SFX_ITEM_DEFAULT: 1393 eState = PropertyState_DEFAULT_VALUE; 1394 break; 1395 // case SFX_ITEM_UNKNOWN: 1396 // case SFX_ITEM_DONTCARE: 1397 // case SFX_ITEM_DISABLED: 1398 default: 1399 eState = PropertyState_AMBIGUOUS_VALUE; 1400 break; 1401 } 1402 1403 // if a item is set, this doesn't mean we want it :) 1404 if( ( PropertyState_DIRECT_VALUE == eState ) ) 1405 { 1406 switch( pMap->nWID ) 1407 { 1408 // the following items are disabled by changing the 1409 // fill style or the line style. so there is no need 1410 // to export items without names which should be empty 1411 case XATTR_FILLBITMAP: 1412 case XATTR_FILLGRADIENT: 1413 case XATTR_FILLHATCH: 1414 case XATTR_LINEDASH: 1415 { 1416 NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID); 1417 if( ( pItem == NULL ) || ( pItem->GetName().Len() == 0) ) 1418 eState = PropertyState_DEFAULT_VALUE; 1419 } 1420 break; 1421 1422 // #i36115# 1423 // If e.g. the LineStart is on NONE and thus the string has length 0, it still 1424 // may be a hard attribute covering the set LineStart of the parent (Style). 1425 // #i37644# 1426 // same is for fill float transparency 1427 case XATTR_LINEEND: 1428 case XATTR_LINESTART: 1429 case XATTR_FILLFLOATTRANSPARENCE: 1430 { 1431 NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID); 1432 if( ( pItem == NULL ) ) 1433 eState = PropertyState_DEFAULT_VALUE; 1434 } 1435 break; 1436 } 1437 } 1438 } 1439 } 1440 return eState; 1441 } 1442 throw UnknownPropertyException(); 1443 } 1444 1445 // ----------------------------------------------------------------------------- 1446 1447 Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException) 1448 { 1449 OGuard aGuard( Application::GetSolarMutex() ); 1450 1451 if( (mpProperties == 0) || (GetModel() == 0) ) 1452 throw DisposedException(); 1453 1454 const sal_Int32 nCount = aPropertyName.getLength(); 1455 1456 Sequence< PropertyState > aRet( nCount ); 1457 1458 const OUString* pNames = aPropertyName.getConstArray(); 1459 PropertyState* pState = aRet.getArray(); 1460 1461 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pState++ ) 1462 { 1463 try 1464 { 1465 *pState = getPropertyState( *pNames ); 1466 } 1467 catch( Exception& ) 1468 { 1469 *pState = PropertyState_AMBIGUOUS_VALUE; 1470 } 1471 } 1472 1473 return aRet; 1474 } 1475 1476 // ----------------------------------------------------------------------------- 1477 1478 void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException) 1479 { 1480 OGuard aGuard( Application::GetSolarMutex() ); 1481 1482 if( (mpProperties == 0) || (GetModel() == 0) ) 1483 throw DisposedException(); 1484 1485 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); 1486 if( pMap ) 1487 { 1488 switch( pMap->nWID ) 1489 { 1490 case OWN_ATTR_FILLBMP_MODE: 1491 { 1492 mpProperties->ClearObjectItem( XATTR_FILLBMP_STRETCH ); 1493 mpProperties->ClearObjectItem( XATTR_FILLBMP_TILE ); 1494 break; 1495 } 1496 // case OWN_ATTR_HASLEVELS: 1497 case OWN_ATTR_STYLE: 1498 break; 1499 1500 case OWN_ATTR_TABLEBORDER: 1501 { 1502 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER_INNER ); 1503 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER ); 1504 break; 1505 } 1506 1507 default: 1508 { 1509 mpProperties->ClearObjectItem( pMap->nWID ); 1510 } 1511 } 1512 1513 GetModel()->SetChanged(); 1514 return; 1515 } 1516 throw UnknownPropertyException(); 1517 } 1518 1519 // ----------------------------------------------------------------------------- 1520 1521 Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException) 1522 { 1523 OGuard aGuard( Application::GetSolarMutex() ); 1524 1525 if( (mpProperties == 0) || (GetModel() == 0) ) 1526 throw DisposedException(); 1527 1528 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName); 1529 if( pMap ) 1530 { 1531 switch( pMap->nWID ) 1532 { 1533 case OWN_ATTR_FILLBMP_MODE: 1534 return Any( BitmapMode_NO_REPEAT ); 1535 1536 /* 1537 case OWN_ATTR_HASLEVELS: 1538 return Any( sal_False ); 1539 */ 1540 case OWN_ATTR_STYLE: 1541 { 1542 Reference< XStyle > xStyle; 1543 return Any( xStyle ); 1544 } 1545 1546 case OWN_ATTR_TABLEBORDER: 1547 { 1548 TableBorder aBorder; 1549 return Any( aBorder ); 1550 } 1551 1552 default: 1553 { 1554 if( GetModel()->GetItemPool().IsWhich(pMap->nWID) ) 1555 { 1556 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID); 1557 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); 1558 return GetAnyForItem( aSet, pMap ); 1559 } 1560 } 1561 } 1562 } 1563 throw UnknownPropertyException(); 1564 } 1565 1566 // ----------------------------------------------------------------------------- 1567 // XMultiPropertyStates 1568 // ----------------------------------------------------------------------------- 1569 1570 void SAL_CALL Cell::setAllPropertiesToDefault( ) throw (RuntimeException) 1571 { 1572 if( mpProperties ) 1573 delete mpProperties; 1574 mpProperties = new sdr::properties::CellProperties( static_cast< SdrTableObj& >( GetObject() ), this ); 1575 1576 SdrOutliner& rOutliner = GetObject().ImpGetDrawOutliner(); 1577 1578 OutlinerParaObject* pParaObj = GetOutlinerParaObject(); 1579 if( pParaObj ) 1580 { 1581 rOutliner.SetText(*pParaObj); 1582 sal_uInt32 nParaCount(rOutliner.GetParagraphCount()); 1583 1584 if(nParaCount) 1585 { 1586 ESelection aSelection( 0, 0, EE_PARA_ALL, EE_PARA_ALL); 1587 rOutliner.RemoveAttribs(aSelection, sal_True, 0); 1588 1589 OutlinerParaObject* pTemp = rOutliner.CreateParaObject(0, (sal_uInt16)nParaCount); 1590 rOutliner.Clear(); 1591 1592 SetOutlinerParaObject(pTemp); 1593 } 1594 } 1595 } 1596 1597 // ----------------------------------------------------------------------------- 1598 1599 void SAL_CALL Cell::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, RuntimeException) 1600 { 1601 sal_Int32 nCount = aPropertyNames.getLength(); 1602 const OUString* pName = aPropertyNames.getConstArray(); 1603 1604 while(nCount--) 1605 setPropertyToDefault( *pName++ ); 1606 } 1607 1608 // ----------------------------------------------------------------------------- 1609 1610 Sequence< Any > SAL_CALL Cell::getPropertyDefaults( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) 1611 { 1612 sal_Int32 nCount = aPropertyNames.getLength(); 1613 Sequence< Any > aDefaults( nCount ); 1614 Any* pDefaults = aDefaults.getArray(); 1615 const OUString* pName = aPropertyNames.getConstArray(); 1616 1617 while(nCount--) 1618 *pDefaults++ = getPropertyDefault( *pName++ ); 1619 1620 return aDefaults; 1621 } 1622 1623 // ----------------------------------------------------------------------------- 1624 // XFastPropertySet 1625 // ----------------------------------------------------------------------------- 1626 1627 void SAL_CALL Cell::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException) 1628 { 1629 (void)aValue; 1630 (void)nHandle; 1631 throw UnknownPropertyException(); 1632 } 1633 1634 // ----------------------------------------------------------------------------- 1635 // TODO: Refactor this method! 1636 Any SAL_CALL Cell::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) 1637 { 1638 (void)nHandle; 1639 throw UnknownPropertyException(); 1640 } 1641 1642 // ----------------------------------------------------------------------------- 1643 // XText 1644 // ----------------------------------------------------------------------------- 1645 1646 void SAL_CALL Cell::insertTextContent( const Reference< XTextRange >& xRange, const Reference< XTextContent >& xContent, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException) 1647 { 1648 SvxUnoTextBase::insertTextContent( xRange, xContent, bAbsorb ); 1649 notifyModified(); 1650 } 1651 1652 // ----------------------------------------------------------------------------- 1653 1654 void SAL_CALL Cell::removeTextContent( const Reference< XTextContent >& xContent ) throw (NoSuchElementException, RuntimeException) 1655 { 1656 SvxUnoTextBase::removeTextContent( xContent ); 1657 notifyModified(); 1658 } 1659 1660 // ----------------------------------------------------------------------------- 1661 // XSimpleText 1662 // ----------------------------------------------------------------------------- 1663 1664 Reference< XTextCursor > SAL_CALL Cell::createTextCursor( ) throw (RuntimeException) 1665 { 1666 return SvxUnoTextBase::createTextCursor(); 1667 } 1668 1669 // ----------------------------------------------------------------------------- 1670 1671 Reference< XTextCursor > SAL_CALL Cell::createTextCursorByRange( const Reference< XTextRange >& aTextPosition ) throw (RuntimeException) 1672 { 1673 return SvxUnoTextBase::createTextCursorByRange( aTextPosition ); 1674 } 1675 1676 // ----------------------------------------------------------------------------- 1677 1678 void SAL_CALL Cell::insertString( const Reference< XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb ) throw (RuntimeException) 1679 { 1680 SvxUnoTextBase::insertString( xRange, aString, bAbsorb ); 1681 notifyModified(); 1682 } 1683 1684 // ----------------------------------------------------------------------------- 1685 1686 void SAL_CALL Cell::insertControlCharacter( const Reference< XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException) 1687 { 1688 SvxUnoTextBase::insertControlCharacter( xRange, nControlCharacter, bAbsorb ); 1689 notifyModified(); 1690 } 1691 1692 // ----------------------------------------------------------------------------- 1693 // XTextRange 1694 // ----------------------------------------------------------------------------- 1695 1696 Reference< XText > SAL_CALL Cell::getText( ) throw (RuntimeException) 1697 { 1698 return SvxUnoTextBase::getText(); 1699 } 1700 1701 // ----------------------------------------------------------------------------- 1702 1703 Reference< XTextRange > SAL_CALL Cell::getStart( ) throw (RuntimeException) 1704 { 1705 return SvxUnoTextBase::getStart(); 1706 } 1707 1708 // ----------------------------------------------------------------------------- 1709 1710 Reference< XTextRange > SAL_CALL Cell::getEnd( ) throw (RuntimeException) 1711 { 1712 return SvxUnoTextBase::getEnd(); 1713 } 1714 1715 // ----------------------------------------------------------------------------- 1716 1717 OUString SAL_CALL Cell::getString( ) throw (RuntimeException) 1718 { 1719 maSelection.nStartPara = 0xffff; 1720 return SvxUnoTextBase::getString(); 1721 } 1722 1723 // ----------------------------------------------------------------------------- 1724 1725 void SAL_CALL Cell::setString( const OUString& aString ) throw (RuntimeException) 1726 { 1727 SvxUnoTextBase::setString( aString ); 1728 notifyModified(); 1729 } 1730 1731 // XEventListener 1732 void SAL_CALL Cell::disposing( const EventObject& /*Source*/ ) throw (RuntimeException) 1733 { 1734 mxTable.clear(); 1735 dispose(); 1736 } 1737 1738 static OUString getCellName( sal_Int32 nCol, sal_Int32 nRow ) 1739 { 1740 rtl::OUStringBuffer aBuf; 1741 1742 if (nCol < 26*26) 1743 { 1744 if (nCol < 26) 1745 aBuf.append( static_cast<sal_Unicode>( 'A' + 1746 static_cast<sal_uInt16>(nCol))); 1747 else 1748 { 1749 aBuf.append( static_cast<sal_Unicode>( 'A' + 1750 (static_cast<sal_uInt16>(nCol) / 26) - 1)); 1751 aBuf.append( static_cast<sal_Unicode>( 'A' + 1752 (static_cast<sal_uInt16>(nCol) % 26))); 1753 } 1754 } 1755 else 1756 { 1757 String aStr; 1758 while (nCol >= 26) 1759 { 1760 sal_Int32 nC = nCol % 26; 1761 aStr += static_cast<sal_Unicode>( 'A' + 1762 static_cast<sal_uInt16>(nC)); 1763 nCol = nCol - nC; 1764 nCol = nCol / 26 - 1; 1765 } 1766 aStr += static_cast<sal_Unicode>( 'A' + 1767 static_cast<sal_uInt16>(nCol)); 1768 aStr.Reverse(); 1769 aBuf.append( aStr); 1770 } 1771 aBuf.append( OUString::valueOf(nRow+1) ); 1772 return aBuf.makeStringAndClear(); 1773 } 1774 1775 OUString Cell::getName() 1776 { 1777 // todo: optimize! 1778 OUString sName; 1779 if( mxTable.is() ) try 1780 { 1781 Reference< XCell > xThis( static_cast< XCell* >( this ) ); 1782 1783 sal_Int32 nRowCount = mxTable->getRowCount(); 1784 sal_Int32 nColCount = mxTable->getColumnCount(); 1785 for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ ) 1786 { 1787 for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ ) 1788 { 1789 Reference< XCell > xCell( mxTable->getCellByPosition( nCol, nRow ) ); 1790 if( xCell == xThis ) 1791 { 1792 return getCellName( nCol, nRow ); 1793 } 1794 } 1795 } 1796 } 1797 catch( Exception& ) 1798 { 1799 } 1800 1801 return sName; 1802 } 1803 1804 } } 1805 1806