update credits
[LibreOffice.git] / svx / source / table / cell.cxx
blobc86662cb6b3419a8b52f370e829723805d08858d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/drawing/BitmapMode.hpp>
22 #include <com/sun/star/style/XStyle.hpp>
23 #include <com/sun/star/text/WritingMode.hpp>
24 #include <com/sun/star/table/TableBorder.hpp>
25 #include <com/sun/star/table/BorderLine2.hpp>
27 #include <comphelper/string.hxx>
29 #include <cppuhelper/typeprovider.hxx>
30 #include <svl/style.hxx>
31 #include <svl/itemset.hxx>
33 #include <osl/mutex.hxx>
34 #include <vcl/svapp.hxx>
36 #include "svx/sdr/properties/textproperties.hxx"
37 #include "editeng/outlobj.hxx"
38 #include "editeng/writingmodeitem.hxx"
39 #include "svx/svdotable.hxx"
40 #include "svx/svdoutl.hxx"
41 #include "svx/unoshtxt.hxx"
42 #include "svx/svdmodel.hxx"
44 #include "tableundo.hxx"
45 #include "cell.hxx"
46 #include "svx/unoshprp.hxx"
47 #include "svx/unoshape.hxx"
48 #include "editeng/editobj.hxx"
49 #include "editeng/boxitem.hxx"
50 #include "svx/xflbstit.hxx"
51 #include "svx/xflbmtit.hxx"
52 #include <svx/svdpool.hxx>
54 // -----------------------------------------------------------------------------
56 using ::editeng::SvxBorderLine;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::beans;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::text;
61 using namespace ::com::sun::star::table;
62 using namespace ::com::sun::star::drawing;
63 using namespace ::com::sun::star::style;
64 using namespace ::com::sun::star::container;
66 // -----------------------------------------------------------------------------
68 static const SvxItemPropertySet* ImplGetSvxCellPropertySet()
70 // Propertymap fuer einen Outliner Text
71 static const SfxItemPropertyMapEntry aSvxCellPropertyMap[] =
73 FILL_PROPERTIES
74 // { MAP_CHAR_LEN("HasLevels"), OWN_ATTR_HASLEVELS, &::getBooleanCppuType(), ::com::sun::star::beans::PropertyAttribute::READONLY, 0},
75 { MAP_CHAR_LEN("Style"), OWN_ATTR_STYLE, &::com::sun::star::style::XStyle::static_type(), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0},
76 { MAP_CHAR_LEN(UNO_NAME_TEXT_WRITINGMODE), SDRATTR_TEXTDIRECTION, &::getCppuType( (::com::sun::star::text::WritingMode*) 0 ), 0, 0},
77 { MAP_CHAR_LEN(UNO_NAME_TEXT_HORZADJUST), SDRATTR_TEXT_HORZADJUST, &::getCppuType((const ::com::sun::star::drawing::TextHorizontalAdjust*)0), 0, 0}, \
78 { MAP_CHAR_LEN(UNO_NAME_TEXT_LEFTDIST), SDRATTR_TEXT_LEFTDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \
79 { MAP_CHAR_LEN(UNO_NAME_TEXT_LOWERDIST), SDRATTR_TEXT_LOWERDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \
80 { MAP_CHAR_LEN(UNO_NAME_TEXT_RIGHTDIST), SDRATTR_TEXT_RIGHTDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \
81 { MAP_CHAR_LEN(UNO_NAME_TEXT_UPPERDIST), SDRATTR_TEXT_UPPERDIST, &::getCppuType((const sal_Int32*)0), 0, SFX_METRIC_ITEM}, \
82 { MAP_CHAR_LEN(UNO_NAME_TEXT_VERTADJUST), SDRATTR_TEXT_VERTADJUST, &::getCppuType((const ::com::sun::star::drawing::TextVerticalAdjust*)0), 0, 0},\
83 { MAP_CHAR_LEN(UNO_NAME_TEXT_WORDWRAP), SDRATTR_TEXT_WORDWRAP, &::getBooleanCppuType(), 0, 0}, \
85 { MAP_CHAR_LEN("TableBorder"), OWN_ATTR_TABLEBORDER, &::getCppuType((const TableBorder*)0), 0, 0 }, \
86 { MAP_CHAR_LEN("TopBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, TOP_BORDER }, \
87 { MAP_CHAR_LEN("BottomBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, BOTTOM_BORDER }, \
88 { MAP_CHAR_LEN("LeftBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, LEFT_BORDER }, \
89 { MAP_CHAR_LEN("RightBorder"), SDRATTR_TABLE_BORDER, &::getCppuType((const BorderLine*)0), 0, RIGHT_BORDER }, \
91 SVX_UNOEDIT_OUTLINER_PROPERTIES,
92 SVX_UNOEDIT_CHAR_PROPERTIES,
93 SVX_UNOEDIT_PARA_PROPERTIES,
94 {0,0,0,0,0,0}
97 static SvxItemPropertySet aSvxCellPropertySet( aSvxCellPropertyMap, SdrObject::GetGlobalDrawObjectItemPool() );
98 return &aSvxCellPropertySet;
101 namespace
104 class CellTextProvider : public svx::ITextProvider
106 public:
107 explicit CellTextProvider(const sdr::table::CellRef xCell);
108 virtual ~CellTextProvider();
110 private:
111 virtual sal_Int32 getTextCount() const;
112 virtual SdrText* getText(sal_Int32 nIndex) const;
114 private:
115 const sdr::table::CellRef m_xCell;
118 CellTextProvider::CellTextProvider(const sdr::table::CellRef xCell)
119 : m_xCell(xCell)
123 CellTextProvider::~CellTextProvider()
127 sal_Int32 CellTextProvider::getTextCount() const
129 return 1;
132 SdrText* CellTextProvider::getText(sal_Int32 nIndex) const
134 (void) nIndex;
135 assert(nIndex == 0);
136 return m_xCell.get();
141 namespace sdr
143 namespace properties
145 class CellProperties : public TextProperties
147 protected:
148 // create a new itemset
149 SfxItemSet& CreateObjectSpecificItemSet(SfxItemPool& rPool);
151 const svx::ITextProvider& getTextProvider() const;
153 public:
154 // basic constructor
155 CellProperties(SdrObject& rObj, sdr::table::Cell* pCell );
157 // constructor for copying, but using new object
158 CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell);
160 // destructor
161 ~CellProperties();
163 // Clone() operator, normally just calls the local copy constructor
164 BaseProperties& Clone(SdrObject& rObj) const;
166 void ForceDefaultAttributes();
168 void ItemSetChanged(const SfxItemSet& rSet);
170 void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem);
172 void SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr);
174 sdr::table::CellRef mxCell;
176 private:
177 const CellTextProvider maTextProvider;
180 // create a new itemset
181 SfxItemSet& CellProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
183 return *(new SfxItemSet(rPool,
185 // range from SdrAttrObj
186 SDRATTR_START, SDRATTR_SHADOW_LAST,
187 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
188 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
190 // range for SdrTableObj
191 SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST,
193 // range from SdrTextObj
194 EE_ITEMS_START, EE_ITEMS_END,
196 // end
197 0, 0));
200 const svx::ITextProvider& CellProperties::getTextProvider() const
202 return maTextProvider;
205 CellProperties::CellProperties(SdrObject& rObj, sdr::table::Cell* pCell)
206 : TextProperties(rObj)
207 , mxCell(pCell)
208 , maTextProvider(mxCell)
212 CellProperties::CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell)
213 : TextProperties(rProps, rObj)
214 , mxCell( pCell )
215 , maTextProvider(mxCell)
219 CellProperties::~CellProperties()
223 BaseProperties& CellProperties::Clone(SdrObject& rObj) const
225 OSL_FAIL("CellProperties::Clone(), does not work yet!");
226 return *(new CellProperties(*this, rObj,0));
229 void CellProperties::ForceDefaultAttributes()
233 void CellProperties::ItemSetChanged(const SfxItemSet& rSet )
235 SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
237 if( mxCell.is() )
239 OutlinerParaObject* pParaObj = mxCell->GetEditOutlinerParaObject();
241 bool bOwnParaObj = pParaObj != 0;
243 if( pParaObj == 0 )
244 pParaObj = mxCell->GetOutlinerParaObject();
246 if(pParaObj)
248 // handle outliner attributes
249 Outliner* pOutliner = 0;
251 if(mxCell->IsTextEditActive())
253 pOutliner = rObj.GetTextEditOutliner();
255 else
257 pOutliner = &rObj.ImpGetDrawOutliner();
258 pOutliner->SetText(*pParaObj);
261 sal_Int32 nParaCount(pOutliner->GetParagraphCount());
263 for(sal_Int32 nPara = 0; nPara < nParaCount; nPara++)
265 SfxItemSet aSet(pOutliner->GetParaAttribs(nPara));
266 aSet.Put(rSet);
267 pOutliner->SetParaAttribs(nPara, aSet);
270 if(!mxCell->IsTextEditActive())
272 if(nParaCount)
274 // force ItemSet
275 GetObjectItemSet();
277 SfxItemSet aNewSet(pOutliner->GetParaAttribs(0L));
278 mpItemSet->Put(aNewSet);
281 OutlinerParaObject* pTemp = pOutliner->CreateParaObject(0, nParaCount);
282 pOutliner->Clear();
284 mxCell->SetOutlinerParaObject(pTemp);
287 if( bOwnParaObj )
288 delete pParaObj;
292 // call parent
293 AttributeProperties::ItemSetChanged(rSet);
295 if( mxCell.is() )
296 mxCell->notifyModified();
299 void CellProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
301 if(pNewItem && (SDRATTR_TEXTDIRECTION == nWhich))
303 sal_Bool bVertical(com::sun::star::text::WritingMode_TB_RL == ((SvxWritingModeItem*)pNewItem)->GetValue());
305 sdr::table::SdrTableObj& rObj = (sdr::table::SdrTableObj&)GetSdrObject();
306 if( rObj.IsVerticalWriting() != bVertical )
307 rObj.SetVerticalWriting(bVertical);
309 // Set a cell vertical property
310 OutlinerParaObject* pParaObj = mxCell->GetEditOutlinerParaObject();
311 if( pParaObj == 0 )
312 pParaObj = mxCell->GetOutlinerParaObject();
313 if(pParaObj)
315 pParaObj->SetVertical(bVertical);
320 // call parent
321 AttributeProperties::ItemChange( nWhich, pNewItem );
324 void CellProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
326 TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
328 } // end of namespace properties
329 } // end of namespace sdr
331 namespace sdr { namespace table {
333 // -----------------------------------------------------------------------------
334 // Cell
335 // -----------------------------------------------------------------------------
337 rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject )
339 rtl::Reference< Cell > xCell( new Cell( rTableObj, pOutlinerParaObject ) );
340 if( xCell->mxTable.is() )
342 Reference< XEventListener > xListener( xCell.get() );
343 xCell->mxTable->addEventListener( xListener );
345 return xCell;
348 // -----------------------------------------------------------------------------
350 Cell::Cell( SdrTableObj& rTableObj, OutlinerParaObject* pOutlinerParaObject ) throw()
351 : SdrText( rTableObj, pOutlinerParaObject )
352 , SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
353 , mpPropSet( ImplGetSvxCellPropertySet() )
354 , mpProperties( new sdr::properties::CellProperties( rTableObj, this ) )
355 , mnCellContentType( CellContentType_EMPTY )
356 , mfValue( 0.0 )
357 , mnError( 0 )
358 , mbMerged( sal_False )
359 , mnRowSpan( 1 )
360 , mnColSpan( 1 )
361 , mxTable( rTableObj.getTable() )
363 if( rTableObj.GetModel() )
364 SetModel( rTableObj.GetModel() );
367 // -----------------------------------------------------------------------------
369 Cell::~Cell() throw()
371 dispose();
374 // -----------------------------------------------------------------------------
376 void Cell::dispose()
378 if( mxTable.is() )
382 Reference< XEventListener > xThis( this );
383 mxTable->removeEventListener( xThis );
385 catch( Exception& )
387 OSL_FAIL("Cell::dispose(), exception caught!");
389 mxTable.clear();
392 if( mpProperties )
394 delete mpProperties;
395 mpProperties = 0;
397 SetOutlinerParaObject( 0 );
400 // -----------------------------------------------------------------------------
402 void Cell::SetModel(SdrModel* pNewModel)
404 SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( GetEditSource() );
405 if( (GetModel() != pNewModel) || ( pNewModel && !pTextEditSource) )
407 if( mpProperties )
409 SfxItemPool* pItemPool = mpProperties->GetObjectItemSet().GetPool();
411 // test for correct pool in ItemSet; move to new pool if necessary
412 if( pNewModel && pItemPool && pItemPool != &pNewModel->GetItemPool())
413 mpProperties->MoveToItemPool(pItemPool, &pNewModel->GetItemPool(), pNewModel);
416 if( pTextEditSource )
418 pTextEditSource->ChangeModel( pNewModel );
420 else
422 SetEditSource( new SvxTextEditSource( &GetObject(), this, static_cast< XWeak * >( this ) ) );
425 SetStyleSheet( 0, sal_True );
426 SdrText::SetModel( pNewModel );
427 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
431 // -----------------------------------------------------------------------------
433 void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
435 if( (mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || (mbMerged != sal_False) )
437 mnColSpan = nColumnSpan;
438 mnRowSpan = nRowSpan;
439 mbMerged = sal_False;
440 notifyModified();
444 // -----------------------------------------------------------------------------
446 void Cell::mergeContent( const CellRef& xSourceCell )
448 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
450 if( xSourceCell->hasText() )
452 SdrOutliner& rOutliner=rTableObj.ImpGetDrawOutliner();
453 rOutliner.SetUpdateMode(sal_True);
455 if( hasText() )
457 rOutliner.SetText(*GetOutlinerParaObject());
458 rOutliner.AddText(*xSourceCell->GetOutlinerParaObject());
460 else
462 rOutliner.SetText(*xSourceCell->GetOutlinerParaObject());
465 SetOutlinerParaObject( rOutliner.CreateParaObject() );
466 rOutliner.Clear();
467 xSourceCell->SetOutlinerParaObject(rOutliner.CreateParaObject());
468 rOutliner.Clear();
469 SetStyleSheet( GetStyleSheet(), sal_True );
473 // -----------------------------------------------------------------------------
475 void Cell::cloneFrom( const CellRef& xCell )
477 if( xCell.is() )
479 replaceContentAndFormating( xCell );
481 mnCellContentType = xCell->mnCellContentType;
483 msFormula = xCell->msFormula;
484 mfValue = xCell->mfValue;
485 mnError = xCell->mnError;
487 mbMerged = xCell->mbMerged;
488 mnRowSpan = xCell->mnRowSpan;
489 mnColSpan = xCell->mnColSpan;
492 notifyModified();
495 void Cell::replaceContentAndFormating( const CellRef& xSourceCell )
497 if( xSourceCell.is() && mpProperties )
499 mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );
500 SetOutlinerParaObject( new OutlinerParaObject(*xSourceCell->GetOutlinerParaObject()) );
502 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
503 SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );
505 if(rSourceTableObj.GetModel() != rTableObj.GetModel())
507 SetStyleSheet( 0, sal_True );
512 // -----------------------------------------------------------------------------
514 void Cell::setMerged()
516 if( !mbMerged )
518 mbMerged = sal_True;
519 notifyModified();
523 // -----------------------------------------------------------------------------
525 void Cell::notifyModified()
527 if( mxTable.is() )
528 mxTable->setModified( sal_True );
531 // -----------------------------------------------------------------------------
532 // SdrTextShape proxy
533 // -----------------------------------------------------------------------------
535 bool Cell::IsTextEditActive()
537 bool isActive = false;
538 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
539 if(rTableObj.getActiveCell().get() == this )
541 OutlinerParaObject* pParaObj = rTableObj.GetEditOutlinerParaObject();
542 if( pParaObj != 0 )
544 isActive = true;
545 delete pParaObj;
548 return isActive;
551 // -----------------------------------------------------------------------------
553 bool Cell::hasText() const
555 OutlinerParaObject* pParaObj = GetOutlinerParaObject();
556 if( pParaObj )
558 const EditTextObject& rTextObj = pParaObj->GetTextObject();
559 if( rTextObj.GetParagraphCount() >= 1 )
561 if( rTextObj.GetParagraphCount() == 1 )
563 if( rTextObj.GetText(0).Len() == 0 )
564 return false;
566 return true;
570 return false;
573 // -----------------------------------------------------------------------------
575 OutlinerParaObject* Cell::GetEditOutlinerParaObject() const
577 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
578 if( rTableObj.getActiveCell().get() == this )
579 return rTableObj.GetEditOutlinerParaObject();
580 return 0;
583 // -----------------------------------------------------------------------------
585 void Cell::SetStyleSheet( SfxStyleSheet* pStyleSheet, sal_Bool bDontRemoveHardAttr )
587 // only allow cell styles for cells
588 if( pStyleSheet && pStyleSheet->GetFamily() != SFX_STYLE_FAMILY_FRAME )
589 return;
591 if( mpProperties && (mpProperties->GetStyleSheet() != pStyleSheet) )
593 mpProperties->SetStyleSheet( pStyleSheet, bDontRemoveHardAttr );
597 // -----------------------------------------------------------------------------
599 const SfxItemSet& Cell::GetObjectItemSet()
601 if( mpProperties )
603 return mpProperties->GetObjectItemSet();
605 else
607 OSL_FAIL("Cell::GetObjectItemSet(), called without properties!");
608 return GetObject().GetObjectItemSet();
612 void Cell::SetObjectItem(const SfxPoolItem& rItem)
614 if( mpProperties )
616 mpProperties->SetObjectItem( rItem );
617 notifyModified();
621 void Cell::SetMergedItem(const SfxPoolItem& rItem)
623 SetObjectItem(rItem);
626 SfxStyleSheet* Cell::GetStyleSheet() const
628 if( mpProperties )
629 return mpProperties->GetStyleSheet();
630 else
631 return 0;
634 // -----------------------------------------------------------------------------
636 const Rectangle& Cell::GetCurrentBoundRect() const
638 return maCellRect;
641 // -----------------------------------------------------------------------------
643 void Cell::TakeTextAnchorRect(Rectangle& rAnchorRect) const
645 rAnchorRect.Left() = maCellRect.Left() + GetTextLeftDistance();
646 rAnchorRect.Right() = maCellRect.Right() - GetTextRightDistance();
647 rAnchorRect.Top() = maCellRect.Top() + GetTextUpperDistance();
648 rAnchorRect.Bottom() = maCellRect.Bottom() - GetTextLowerDistance();
651 // -----------------------------------------------------------------------------
653 const SfxItemSet& Cell::GetItemSet() const
655 return mpProperties->GetObjectItemSet();
658 // -----------------------------------------------------------------------------
660 void Cell::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, sal_Bool bClearAllItems)
662 if( mpProperties )
664 mpProperties->SetMergedItemSetAndBroadcast(rSet, bClearAllItems);
665 notifyModified();
669 // -----------------------------------------------------------------------------
671 sal_Int32 Cell::getMinimumWidth()
673 return GetTextLeftDistance() + GetTextRightDistance() + 100;
676 // -----------------------------------------------------------------------------
678 sal_Int32 Cell::getMinimumHeight()
680 if( !mpProperties )
681 return 0;
683 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
684 sal_Int32 nMinimumHeight = 0;
686 Rectangle aTextRect;
687 TakeTextAnchorRect( aTextRect );
688 Size aSize( aTextRect.GetSize() );
689 aSize.Height()=0x0FFFFFFF;
691 SdrOutliner* pEditOutliner = rTableObj.GetCellTextEditOutliner( *this );
692 if(pEditOutliner)
694 pEditOutliner->SetMaxAutoPaperSize(aSize);
695 nMinimumHeight = pEditOutliner->GetTextHeight()+1;
697 else /*if ( hasText() )*/
699 Outliner& rOutliner=rTableObj.ImpGetDrawOutliner();
700 rOutliner.SetPaperSize(aSize);
701 rOutliner.SetUpdateMode(sal_True);
702 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
704 if( GetOutlinerParaObject() )
706 rOutliner.SetText(*GetOutlinerParaObject());
708 nMinimumHeight=rOutliner.GetTextHeight()+1;
709 rOutliner.Clear();
712 nMinimumHeight += GetTextUpperDistance() + GetTextLowerDistance();
713 return nMinimumHeight;
716 // -----------------------------------------------------------------------------
718 long Cell::GetTextLeftDistance() const
720 return ((SdrTextLeftDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LEFTDIST))).GetValue();
723 // -----------------------------------------------------------------------------
725 long Cell::GetTextRightDistance() const
727 return ((SdrTextRightDistItem&)(GetItemSet().Get(SDRATTR_TEXT_RIGHTDIST))).GetValue();
730 // -----------------------------------------------------------------------------
732 long Cell::GetTextUpperDistance() const
734 return ((SdrTextUpperDistItem&)(GetItemSet().Get(SDRATTR_TEXT_UPPERDIST))).GetValue();
737 // -----------------------------------------------------------------------------
739 long Cell::GetTextLowerDistance() const
741 return ((SdrTextLowerDistItem&)(GetItemSet().Get(SDRATTR_TEXT_LOWERDIST))).GetValue();
744 // -----------------------------------------------------------------------------
746 SdrTextVertAdjust Cell::GetTextVerticalAdjust() const
748 return ((SdrTextVertAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_VERTADJUST))).GetValue();
751 // -----------------------------------------------------------------------------
753 SdrTextHorzAdjust Cell::GetTextHorizontalAdjust() const
755 return ((SdrTextHorzAdjustItem&)(GetItemSet().Get(SDRATTR_TEXT_HORZADJUST))).GetValue();
758 // -----------------------------------------------------------------------------
760 void Cell::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
762 SdrText::SetOutlinerParaObject( pTextObject );
763 maSelection.nStartPara = EE_PARA_MAX_COUNT;
765 if( pTextObject == 0 )
766 ForceOutlinerParaObject( OUTLINERMODE_TEXTOBJECT );
769 // -----------------------------------------------------------------------------
771 void Cell::AddUndo()
773 SdrObject& rObj = GetObject();
774 if( rObj.IsInserted() && GetModel() && GetModel()->IsUndoEnabled() )
776 CellRef xCell( this );
777 GetModel()->AddUndo( new CellUndo( &rObj, xCell ) );
781 // -----------------------------------------------------------------------------
783 sdr::properties::TextProperties* Cell::CloneProperties( sdr::properties::TextProperties* pProperties, SdrObject& rNewObj, Cell& rNewCell )
785 if( pProperties )
786 return new sdr::properties::CellProperties( *static_cast<sdr::properties::CellProperties*>(pProperties), rNewObj, &rNewCell );
787 else
788 return 0;
791 // -----------------------------------------------------------------------------
793 sdr::properties::TextProperties* Cell::CloneProperties( SdrObject& rNewObj, Cell& rNewCell )
795 return CloneProperties(mpProperties,rNewObj,rNewCell);
798 // -----------------------------------------------------------------------------
799 // XInterface
800 // -----------------------------------------------------------------------------
802 Any SAL_CALL Cell::queryInterface( const Type & rType ) throw(RuntimeException)
804 if( rType == XMergeableCell::static_type() )
805 return Any( Reference< XMergeableCell >( this ) );
807 if( rType == XCell::static_type() )
808 return Any( Reference< XCell >( this ) );
810 if( rType == XLayoutConstrains::static_type() )
811 return Any( Reference< XLayoutConstrains >( this ) );
813 if( rType == XEventListener::static_type() )
814 return Any( Reference< XEventListener >( this ) );
816 Any aRet( SvxUnoTextBase::queryAggregation( rType ) );
817 if( aRet.hasValue() )
818 return aRet;
820 return ::cppu::OWeakObject::queryInterface( rType );
823 // -----------------------------------------------------------------------------
825 void SAL_CALL Cell::acquire() throw ()
827 ::cppu::OWeakObject::acquire();
830 // -----------------------------------------------------------------------------
832 void SAL_CALL Cell::release() throw ()
834 ::cppu::OWeakObject::release();
837 // -----------------------------------------------------------------------------
838 // XTypeProvider
839 // -----------------------------------------------------------------------------
841 Sequence< Type > SAL_CALL Cell::getTypes( ) throw (RuntimeException)
843 Sequence< Type > aTypes( SvxUnoTextBase::getTypes() );
845 sal_Int32 nLen = aTypes.getLength();
846 aTypes.realloc(nLen + 2);
847 aTypes[nLen++] = XMergeableCell::static_type();
848 aTypes[nLen++] = XLayoutConstrains::static_type();
850 return aTypes;
853 // -----------------------------------------------------------------------------
855 Sequence< sal_Int8 > SAL_CALL Cell::getImplementationId( ) throw (RuntimeException)
857 static ::cppu::OImplementationId* pId = 0;
858 if (! pId)
860 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
861 if (! pId)
863 static ::cppu::OImplementationId aId;
864 pId = &aId;
867 return pId->getImplementationId();
870 // -----------------------------------------------------------------------------
871 // XServiceInfo
872 // -----------------------------------------------------------------------------
874 OUString SAL_CALL Cell::getImplementationName( ) throw (RuntimeException)
876 return OUString( "com.sun.star.comp.svx.table.Cell" );
879 // -----------------------------------------------------------------------------
881 sal_Bool SAL_CALL Cell::supportsService( const OUString& ServiceName ) throw (RuntimeException)
883 if( ServiceName == "com.sun.star.table.cell" )
884 return sal_True;
886 if( ServiceName == "com.sun.star.drawing.cell" )
887 return sal_True;
889 return SvxUnoTextBase::supportsService( ServiceName );
892 // -----------------------------------------------------------------------------
894 Sequence< OUString > SAL_CALL Cell::getSupportedServiceNames( ) throw (RuntimeException)
896 Sequence< OUString > aSeq( SvxUnoTextBase::getSupportedServiceNames() );
897 sal_Int32 nIndex = aSeq.getLength();
898 aSeq.realloc( nIndex + 2 );
899 aSeq[nIndex++] = OUString( "com.sun.star.table.cell" );
900 aSeq[nIndex++] = OUString( "com.sun.star.drawing.cell" );
901 return aSeq;
904 // -----------------------------------------------------------------------------
905 // XLayoutConstrains
906 // -----------------------------------------------------------------------------
908 ::com::sun::star::awt::Size SAL_CALL Cell::getMinimumSize( ) throw (RuntimeException)
910 return ::com::sun::star::awt::Size( getMinimumWidth(), getMinimumHeight() );
913 // -----------------------------------------------------------------------------
915 ::com::sun::star::awt::Size SAL_CALL Cell::getPreferredSize( ) throw (RuntimeException)
917 return getMinimumSize();
920 // -----------------------------------------------------------------------------
922 ::com::sun::star::awt::Size SAL_CALL Cell::calcAdjustedSize( const ::com::sun::star::awt::Size& aNewSize ) throw (RuntimeException)
924 return aNewSize;
927 // -----------------------------------------------------------------------------
928 // XMergeableCell
929 // -----------------------------------------------------------------------------
931 sal_Int32 SAL_CALL Cell::getRowSpan() throw (RuntimeException)
933 return mnRowSpan;
936 // -----------------------------------------------------------------------------
938 sal_Int32 SAL_CALL Cell::getColumnSpan() throw (RuntimeException)
940 return mnColSpan;
943 // -----------------------------------------------------------------------------
945 sal_Bool SAL_CALL Cell::isMerged() throw (RuntimeException)
947 return mbMerged;
950 // -----------------------------------------------------------------------------
951 // XCell
952 // -----------------------------------------------------------------------------
954 OUString SAL_CALL Cell::getFormula( ) throw (RuntimeException)
956 return msFormula;
959 // -----------------------------------------------------------------------------
961 void SAL_CALL Cell::setFormula( const OUString& aFormula ) throw (RuntimeException)
963 if( msFormula != aFormula )
965 msFormula = aFormula;
969 // -----------------------------------------------------------------------------
971 double SAL_CALL Cell::getValue( ) throw (RuntimeException)
973 return mfValue;
976 // -----------------------------------------------------------------------------
978 void SAL_CALL Cell::setValue( double nValue ) throw (RuntimeException)
980 if( mfValue != nValue )
982 mfValue = nValue;
983 mnCellContentType = CellContentType_VALUE;
987 // -----------------------------------------------------------------------------
989 CellContentType SAL_CALL Cell::getType() throw (RuntimeException)
991 return mnCellContentType;
994 // -----------------------------------------------------------------------------
996 sal_Int32 SAL_CALL Cell::getError( ) throw (RuntimeException)
998 return mnError;
1001 // -----------------------------------------------------------------------------
1002 // XPropertySet
1003 // -----------------------------------------------------------------------------
1005 Any Cell::GetAnyForItem( SfxItemSet& aSet, const SfxItemPropertySimpleEntry* pMap )
1007 Any aAny( SvxItemPropertySet_getPropertyValue( *mpPropSet, pMap, aSet ) );
1009 if( *pMap->pType != aAny.getValueType() )
1011 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
1012 if( ( *pMap->pType == ::getCppuType((const sal_Int16*)0)) && aAny.getValueType() == ::getCppuType((const sal_Int32*)0) )
1014 sal_Int32 nValue = 0;
1015 aAny >>= nValue;
1016 aAny <<= (sal_Int16)nValue;
1018 else
1020 OSL_FAIL("GetAnyForItem() Returnvalue has wrong Type!" );
1024 return aAny;
1027 Reference< XPropertySetInfo > SAL_CALL Cell::getPropertySetInfo() throw(RuntimeException)
1029 return mpPropSet->getPropertySetInfo();
1032 // -----------------------------------------------------------------------------
1034 void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1036 ::SolarMutexGuard aGuard;
1038 if( (mpProperties == 0) || (GetModel() == 0) )
1039 throw DisposedException();
1041 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName);
1042 if( pMap )
1044 if( (pMap->nFlags & PropertyAttribute::READONLY ) != 0 )
1045 throw PropertyVetoException();
1047 switch( pMap->nWID )
1049 case OWN_ATTR_STYLE:
1051 Reference< XStyle > xStyle;
1052 if( !( rValue >>= xStyle ) )
1053 throw IllegalArgumentException();
1055 SfxUnoStyleSheet* pStyle = SfxUnoStyleSheet::getUnoStyleSheet(xStyle);
1056 SetStyleSheet( pStyle, sal_True );
1057 return;
1059 case OWN_ATTR_TABLEBORDER:
1061 if(rValue.getValueType() != ::getCppuType((const TableBorder*)0) )
1062 break;
1064 const TableBorder* pBorder = (const TableBorder* )rValue.getValue();
1065 if( pBorder == NULL )
1066 break;
1068 SvxBoxItem aBox( SDRATTR_TABLE_BORDER );
1069 SvxBoxInfoItem aBoxInfo( SDRATTR_TABLE_BORDER_INNER );
1070 SvxBorderLine aLine;
1072 sal_Bool bSet = SvxBoxItem::LineToSvxLine(pBorder->TopLine, aLine, false);
1073 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_TOP);
1074 aBoxInfo.SetValid(VALID_TOP, pBorder->IsTopLineValid);
1076 bSet = SvxBoxItem::LineToSvxLine(pBorder->BottomLine, aLine, false);
1077 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_BOTTOM);
1078 aBoxInfo.SetValid(VALID_BOTTOM, pBorder->IsBottomLineValid);
1080 bSet = SvxBoxItem::LineToSvxLine(pBorder->LeftLine, aLine, false);
1081 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_LEFT);
1082 aBoxInfo.SetValid(VALID_LEFT, pBorder->IsLeftLineValid);
1084 bSet = SvxBoxItem::LineToSvxLine(pBorder->RightLine, aLine, false);
1085 aBox.SetLine(bSet ? &aLine : 0, BOX_LINE_RIGHT);
1086 aBoxInfo.SetValid(VALID_RIGHT, pBorder->IsRightLineValid);
1088 bSet = SvxBoxItem::LineToSvxLine(pBorder->HorizontalLine, aLine, false);
1089 aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_HORI);
1090 aBoxInfo.SetValid(VALID_HORI, pBorder->IsHorizontalLineValid);
1092 bSet = SvxBoxItem::LineToSvxLine(pBorder->VerticalLine, aLine, false);
1093 aBoxInfo.SetLine(bSet ? &aLine : 0, BOXINFO_LINE_VERT);
1094 aBoxInfo.SetValid(VALID_VERT, pBorder->IsVerticalLineValid);
1096 aBox.SetDistance(pBorder->Distance, false);
1097 aBoxInfo.SetValid(VALID_DISTANCE, pBorder->IsDistanceValid);
1099 mpProperties->SetObjectItem(aBox);
1100 mpProperties->SetObjectItem(aBoxInfo);
1101 return;
1103 case OWN_ATTR_FILLBMP_MODE:
1105 BitmapMode eMode;
1106 if(!(rValue >>= eMode) )
1108 sal_Int32 nMode = 0;
1109 if(!(rValue >>= nMode))
1110 throw IllegalArgumentException();
1112 eMode = (BitmapMode)nMode;
1115 mpProperties->SetObjectItem( XFillBmpStretchItem( eMode == BitmapMode_STRETCH ) );
1116 mpProperties->SetObjectItem( XFillBmpTileItem( eMode == BitmapMode_REPEAT ) );
1117 return;
1119 default:
1121 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1122 aSet.Put(mpProperties->GetItem(pMap->nWID));
1124 bool bSpecial = false;
1126 switch( pMap->nWID )
1128 case XATTR_FILLBITMAP:
1129 case XATTR_FILLGRADIENT:
1130 case XATTR_FILLHATCH:
1131 case XATTR_FILLFLOATTRANSPARENCE:
1132 case XATTR_LINEEND:
1133 case XATTR_LINESTART:
1134 case XATTR_LINEDASH:
1136 if( pMap->nMemberId == MID_NAME )
1138 OUString aApiName;
1139 if( rValue >>= aApiName )
1141 if( SvxShape::SetFillAttribute( pMap->nWID, aApiName, aSet, GetModel() ) )
1142 bSpecial = true;
1146 break;
1149 if( !bSpecial )
1152 if( !SvxUnoTextRangeBase::SetPropertyValueHelper( aSet, pMap, rValue, aSet ))
1154 if( aSet.GetItemState( pMap->nWID ) != SFX_ITEM_SET )
1156 // Default aus ItemPool holen
1157 if(GetModel()->GetItemPool().IsWhich(pMap->nWID))
1158 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1161 if( aSet.GetItemState( pMap->nWID ) == SFX_ITEM_SET )
1163 SvxItemPropertySet_setPropertyValue( *mpPropSet, pMap, rValue, aSet );
1168 GetModel()->SetChanged();
1169 mpProperties->SetMergedItemSetAndBroadcast( aSet );
1170 return;
1174 throw UnknownPropertyException();
1177 // -----------------------------------------------------------------------------
1179 Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1181 ::SolarMutexGuard aGuard;
1183 if( (mpProperties == 0) || (GetModel() == 0) )
1184 throw DisposedException();
1186 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1187 if( pMap )
1189 switch( pMap->nWID )
1191 case OWN_ATTR_STYLE:
1193 return Any( Reference< XStyle >( dynamic_cast< SfxUnoStyleSheet* >( GetStyleSheet() ) ) );
1195 case OWN_ATTR_TABLEBORDER:
1197 const SvxBoxInfoItem& rBoxInfoItem = static_cast<const SvxBoxInfoItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER_INNER));
1198 const SvxBoxItem& rBox = static_cast<const SvxBoxItem&>(mpProperties->GetItem(SDRATTR_TABLE_BORDER));
1200 TableBorder aTableBorder;
1201 aTableBorder.TopLine = SvxBoxItem::SvxLineToLine(rBox.GetTop(), false);
1202 aTableBorder.IsTopLineValid = rBoxInfoItem.IsValid(VALID_TOP);
1203 aTableBorder.BottomLine = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), false);
1204 aTableBorder.IsBottomLineValid = rBoxInfoItem.IsValid(VALID_BOTTOM);
1205 aTableBorder.LeftLine = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), false);
1206 aTableBorder.IsLeftLineValid = rBoxInfoItem.IsValid(VALID_LEFT);
1207 aTableBorder.RightLine = SvxBoxItem::SvxLineToLine(rBox.GetRight(), false);
1208 aTableBorder.IsRightLineValid = rBoxInfoItem.IsValid(VALID_RIGHT );
1209 aTableBorder.HorizontalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), false);
1210 aTableBorder.IsHorizontalLineValid = rBoxInfoItem.IsValid(VALID_HORI);
1211 aTableBorder.VerticalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), false);
1212 aTableBorder.IsVerticalLineValid = rBoxInfoItem.IsValid(VALID_VERT);
1213 aTableBorder.Distance = rBox.GetDistance();
1214 aTableBorder.IsDistanceValid = rBoxInfoItem.IsValid(VALID_DISTANCE);
1216 return Any( aTableBorder );
1218 case OWN_ATTR_FILLBMP_MODE:
1220 const XFillBmpStretchItem& rStretchItem = static_cast<const XFillBmpStretchItem&>(mpProperties->GetItem(XATTR_FILLBMP_STRETCH));
1221 const XFillBmpTileItem& rTileItem = static_cast<const XFillBmpTileItem&>(mpProperties->GetItem(XATTR_FILLBMP_TILE));
1222 if( rTileItem.GetValue() )
1224 return Any( BitmapMode_REPEAT );
1226 else if( rStretchItem.GetValue() )
1228 return Any( BitmapMode_STRETCH );
1230 else
1232 return Any( BitmapMode_NO_REPEAT );
1235 default:
1237 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1238 aSet.Put(mpProperties->GetItem(pMap->nWID));
1240 Any aAny;
1241 if(!SvxUnoTextRangeBase::GetPropertyValueHelper( aSet, pMap, aAny ))
1243 if(!aSet.Count())
1245 // Default aus ItemPool holen
1246 if(GetModel()->GetItemPool().IsWhich(pMap->nWID))
1247 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1250 if( aSet.Count() )
1251 aAny = GetAnyForItem( aSet, pMap );
1254 return aAny;
1258 throw UnknownPropertyException();
1261 // -----------------------------------------------------------------------------
1263 void SAL_CALL Cell::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1267 // -----------------------------------------------------------------------------
1269 void SAL_CALL Cell::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1273 // -----------------------------------------------------------------------------
1275 void SAL_CALL Cell::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1279 // -----------------------------------------------------------------------------
1281 void SAL_CALL Cell::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1285 // -----------------------------------------------------------------------------
1286 // XMultiPropertySet
1287 // -----------------------------------------------------------------------------
1289 void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues ) throw (PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1291 ::SolarMutexGuard aSolarGuard;
1293 if( (mpProperties == 0) || (GetModel() == 0) )
1294 throw DisposedException();
1296 const sal_Int32 nCount = aPropertyNames.getLength();
1298 const OUString* pNames = aPropertyNames.getConstArray();
1299 const Any* pValues = aValues.getConstArray();
1301 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pValues++ )
1305 setPropertyValue( *pNames, *pValues );
1307 catch( UnknownPropertyException& )
1309 OSL_FAIL("svx::Cell::setPropertyValues(), unknown property!" );
1311 catch( Exception& )
1313 OSL_FAIL("svx::Cell::setPropertyValues(), Exception caught!" );
1318 // -----------------------------------------------------------------------------
1320 Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aPropertyNames ) throw (RuntimeException)
1322 ::SolarMutexGuard aSolarGuard;
1324 if( (mpProperties == 0) || (GetModel() == 0) )
1325 throw DisposedException();
1327 const sal_Int32 nCount = aPropertyNames.getLength();
1328 const OUString* pNames = aPropertyNames.getConstArray();
1330 Sequence< Any > aRet( nCount );
1331 Any* pValue = aRet.getArray();
1333 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pValue++, pNames++ )
1337 *pValue = getPropertyValue( *pNames );
1339 catch( UnknownPropertyException& )
1341 OSL_FAIL("svx::Cell::setPropertyValues(), unknown property!" );
1343 catch( Exception& )
1345 OSL_FAIL( "svx::Cell::getPropertyValues(), Exception caught!" );
1349 return aRet;
1352 // -----------------------------------------------------------------------------
1354 void SAL_CALL Cell::addPropertiesChangeListener( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1358 // -----------------------------------------------------------------------------
1360 void SAL_CALL Cell::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1364 // -----------------------------------------------------------------------------
1366 void SAL_CALL Cell::firePropertiesChangeEvent( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ ) throw (RuntimeException)
1370 // -----------------------------------------------------------------------------
1371 // XPropertyState
1372 // -----------------------------------------------------------------------------
1374 PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1376 ::SolarMutexGuard aGuard;
1378 if( (mpProperties == 0) || (GetModel() == 0) )
1379 throw DisposedException();
1381 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1383 if( pMap )
1385 PropertyState eState;
1386 switch( pMap->nWID )
1388 case OWN_ATTR_FILLBMP_MODE:
1390 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1392 const bool bStretch = rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SFX_ITEM_SET;
1393 const bool bTile = rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SFX_ITEM_SET;
1394 if( bStretch || bTile )
1396 eState = PropertyState_DIRECT_VALUE;
1398 else
1400 eState = PropertyState_DEFAULT_VALUE;
1403 case OWN_ATTR_STYLE:
1405 return PropertyState_DIRECT_VALUE;
1407 case OWN_ATTR_TABLEBORDER:
1409 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1410 if( (rSet.GetItemState( SDRATTR_TABLE_BORDER_INNER, sal_False ) == SFX_ITEM_DEFAULT) && (rSet.GetItemState( SDRATTR_TABLE_BORDER, sal_False ) == SFX_ITEM_DEFAULT) )
1411 return PropertyState_DEFAULT_VALUE;
1413 return PropertyState_DIRECT_VALUE;
1415 default:
1417 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1419 switch( rSet.GetItemState( pMap->nWID, sal_False ) )
1421 case SFX_ITEM_READONLY:
1422 case SFX_ITEM_SET:
1423 eState = PropertyState_DIRECT_VALUE;
1424 break;
1425 case SFX_ITEM_DEFAULT:
1426 eState = PropertyState_DEFAULT_VALUE;
1427 break;
1428 default:
1429 eState = PropertyState_AMBIGUOUS_VALUE;
1430 break;
1433 // if a item is set, this doesn't mean we want it :)
1434 if( ( PropertyState_DIRECT_VALUE == eState ) )
1436 switch( pMap->nWID )
1438 // the following items are disabled by changing the
1439 // fill style or the line style. so there is no need
1440 // to export items without names which should be empty
1441 case XATTR_FILLBITMAP:
1442 case XATTR_FILLGRADIENT:
1443 case XATTR_FILLHATCH:
1444 case XATTR_LINEDASH:
1446 NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID);
1447 if( ( pItem == NULL ) || ( pItem->GetName().Len() == 0) )
1448 eState = PropertyState_DEFAULT_VALUE;
1450 break;
1452 // #i36115#
1453 // If e.g. the LineStart is on NONE and thus the string has length 0, it still
1454 // may be a hard attribute covering the set LineStart of the parent (Style).
1455 // #i37644#
1456 // same is for fill float transparency
1457 case XATTR_LINEEND:
1458 case XATTR_LINESTART:
1459 case XATTR_FILLFLOATTRANSPARENCE:
1461 NameOrIndex* pItem = (NameOrIndex*)rSet.GetItem((sal_uInt16)pMap->nWID);
1462 if( pItem == NULL )
1463 eState = PropertyState_DEFAULT_VALUE;
1465 break;
1470 return eState;
1472 throw UnknownPropertyException();
1475 // -----------------------------------------------------------------------------
1477 Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUString >& aPropertyName ) throw(UnknownPropertyException, RuntimeException)
1479 ::SolarMutexGuard aGuard;
1481 if( (mpProperties == 0) || (GetModel() == 0) )
1482 throw DisposedException();
1484 const sal_Int32 nCount = aPropertyName.getLength();
1486 Sequence< PropertyState > aRet( nCount );
1488 const OUString* pNames = aPropertyName.getConstArray();
1489 PropertyState* pState = aRet.getArray();
1491 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pState++ )
1495 *pState = getPropertyState( *pNames );
1497 catch( Exception& )
1499 *pState = PropertyState_AMBIGUOUS_VALUE;
1503 return aRet;
1506 // -----------------------------------------------------------------------------
1508 void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName ) throw(UnknownPropertyException, RuntimeException)
1510 ::SolarMutexGuard aGuard;
1512 if( (mpProperties == 0) || (GetModel() == 0) )
1513 throw DisposedException();
1515 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1516 if( pMap )
1518 switch( pMap->nWID )
1520 case OWN_ATTR_FILLBMP_MODE:
1522 mpProperties->ClearObjectItem( XATTR_FILLBMP_STRETCH );
1523 mpProperties->ClearObjectItem( XATTR_FILLBMP_TILE );
1524 break;
1526 case OWN_ATTR_STYLE:
1527 break;
1529 case OWN_ATTR_TABLEBORDER:
1531 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER_INNER );
1532 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER );
1533 break;
1536 default:
1538 mpProperties->ClearObjectItem( pMap->nWID );
1542 GetModel()->SetChanged();
1543 return;
1545 throw UnknownPropertyException();
1548 // -----------------------------------------------------------------------------
1550 Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
1552 ::SolarMutexGuard aGuard;
1554 if( (mpProperties == 0) || (GetModel() == 0) )
1555 throw DisposedException();
1557 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName);
1558 if( pMap )
1560 switch( pMap->nWID )
1562 case OWN_ATTR_FILLBMP_MODE:
1563 return Any( BitmapMode_NO_REPEAT );
1565 case OWN_ATTR_STYLE:
1567 Reference< XStyle > xStyle;
1568 return Any( xStyle );
1571 case OWN_ATTR_TABLEBORDER:
1573 TableBorder aBorder;
1574 return Any( aBorder );
1577 default:
1579 if( GetModel()->GetItemPool().IsWhich(pMap->nWID) )
1581 SfxItemSet aSet( GetModel()->GetItemPool(), pMap->nWID, pMap->nWID);
1582 aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
1583 return GetAnyForItem( aSet, pMap );
1588 throw UnknownPropertyException();
1591 // -----------------------------------------------------------------------------
1592 // XMultiPropertyStates
1593 // -----------------------------------------------------------------------------
1595 void SAL_CALL Cell::setAllPropertiesToDefault( ) throw (RuntimeException)
1597 delete mpProperties;
1598 mpProperties = new sdr::properties::CellProperties( static_cast< SdrTableObj& >( GetObject() ), this );
1600 SdrOutliner& rOutliner = GetObject().ImpGetDrawOutliner();
1602 OutlinerParaObject* pParaObj = GetOutlinerParaObject();
1603 if( pParaObj )
1605 rOutliner.SetText(*pParaObj);
1606 sal_Int32 nParaCount(rOutliner.GetParagraphCount());
1608 if(nParaCount)
1610 ESelection aSelection( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL);
1611 rOutliner.RemoveAttribs(aSelection, sal_True, 0);
1613 OutlinerParaObject* pTemp = rOutliner.CreateParaObject(0, nParaCount);
1614 rOutliner.Clear();
1616 SetOutlinerParaObject(pTemp);
1621 // -----------------------------------------------------------------------------
1623 void SAL_CALL Cell::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, RuntimeException)
1625 sal_Int32 nCount = aPropertyNames.getLength();
1626 const OUString* pName = aPropertyNames.getConstArray();
1628 while(nCount--)
1629 setPropertyToDefault( *pName++ );
1632 // -----------------------------------------------------------------------------
1634 Sequence< Any > SAL_CALL Cell::getPropertyDefaults( const Sequence< OUString >& aPropertyNames ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1636 sal_Int32 nCount = aPropertyNames.getLength();
1637 Sequence< Any > aDefaults( nCount );
1638 Any* pDefaults = aDefaults.getArray();
1639 const OUString* pName = aPropertyNames.getConstArray();
1641 while(nCount--)
1642 *pDefaults++ = getPropertyDefault( *pName++ );
1644 return aDefaults;
1647 // -----------------------------------------------------------------------------
1648 // XFastPropertySet
1649 // -----------------------------------------------------------------------------
1651 void SAL_CALL Cell::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
1653 (void)aValue;
1654 (void)nHandle;
1655 throw UnknownPropertyException();
1658 // -----------------------------------------------------------------------------
1659 // TODO: Refactor this method!
1660 Any SAL_CALL Cell::getFastPropertyValue( sal_Int32 nHandle ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
1662 (void)nHandle;
1663 throw UnknownPropertyException();
1666 // -----------------------------------------------------------------------------
1667 // XText
1668 // -----------------------------------------------------------------------------
1670 void SAL_CALL Cell::insertTextContent( const Reference< XTextRange >& xRange, const Reference< XTextContent >& xContent, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException)
1672 SvxUnoTextBase::insertTextContent( xRange, xContent, bAbsorb );
1673 notifyModified();
1676 // -----------------------------------------------------------------------------
1678 void SAL_CALL Cell::removeTextContent( const Reference< XTextContent >& xContent ) throw (NoSuchElementException, RuntimeException)
1680 SvxUnoTextBase::removeTextContent( xContent );
1681 notifyModified();
1684 // -----------------------------------------------------------------------------
1685 // XSimpleText
1686 // -----------------------------------------------------------------------------
1688 Reference< XTextCursor > SAL_CALL Cell::createTextCursor( ) throw (RuntimeException)
1690 return SvxUnoTextBase::createTextCursor();
1693 // -----------------------------------------------------------------------------
1695 Reference< XTextCursor > SAL_CALL Cell::createTextCursorByRange( const Reference< XTextRange >& aTextPosition ) throw (RuntimeException)
1697 return SvxUnoTextBase::createTextCursorByRange( aTextPosition );
1700 // -----------------------------------------------------------------------------
1702 void SAL_CALL Cell::insertString( const Reference< XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb ) throw (RuntimeException)
1704 SvxUnoTextBase::insertString( xRange, aString, bAbsorb );
1705 notifyModified();
1708 // -----------------------------------------------------------------------------
1710 void SAL_CALL Cell::insertControlCharacter( const Reference< XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb ) throw (IllegalArgumentException, RuntimeException)
1712 SvxUnoTextBase::insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1713 notifyModified();
1716 // -----------------------------------------------------------------------------
1717 // XTextRange
1718 // -----------------------------------------------------------------------------
1720 Reference< XText > SAL_CALL Cell::getText( ) throw (RuntimeException)
1722 return SvxUnoTextBase::getText();
1725 // -----------------------------------------------------------------------------
1727 Reference< XTextRange > SAL_CALL Cell::getStart( ) throw (RuntimeException)
1729 return SvxUnoTextBase::getStart();
1732 // -----------------------------------------------------------------------------
1734 Reference< XTextRange > SAL_CALL Cell::getEnd( ) throw (RuntimeException)
1736 return SvxUnoTextBase::getEnd();
1739 // -----------------------------------------------------------------------------
1741 OUString SAL_CALL Cell::getString( ) throw (RuntimeException)
1743 maSelection.nStartPara = EE_PARA_MAX_COUNT;
1744 return SvxUnoTextBase::getString();
1747 // -----------------------------------------------------------------------------
1749 void SAL_CALL Cell::setString( const OUString& aString ) throw (RuntimeException)
1751 SvxUnoTextBase::setString( aString );
1752 notifyModified();
1755 // XEventListener
1756 void SAL_CALL Cell::disposing( const EventObject& /*Source*/ ) throw (RuntimeException)
1758 mxTable.clear();
1759 dispose();
1762 static OUString getCellName( sal_Int32 nCol, sal_Int32 nRow )
1764 OUStringBuffer aBuf;
1766 if (nCol < 26*26)
1768 if (nCol < 26)
1769 aBuf.append( static_cast<sal_Unicode>( 'A' +
1770 static_cast<sal_uInt16>(nCol)));
1771 else
1773 aBuf.append( static_cast<sal_Unicode>( 'A' +
1774 (static_cast<sal_uInt16>(nCol) / 26) - 1));
1775 aBuf.append( static_cast<sal_Unicode>( 'A' +
1776 (static_cast<sal_uInt16>(nCol) % 26)));
1779 else
1781 String aStr;
1782 while (nCol >= 26)
1784 sal_Int32 nC = nCol % 26;
1785 aStr += static_cast<sal_Unicode>( 'A' +
1786 static_cast<sal_uInt16>(nC));
1787 nCol = nCol - nC;
1788 nCol = nCol / 26 - 1;
1790 aStr += static_cast<sal_Unicode>( 'A' +
1791 static_cast<sal_uInt16>(nCol));
1792 aBuf.append(comphelper::string::reverseString(aStr));
1794 aBuf.append( OUString::valueOf(nRow+1) );
1795 return aBuf.makeStringAndClear();
1798 OUString Cell::getName()
1800 // todo: optimize!
1801 OUString sName;
1802 if( mxTable.is() ) try
1804 Reference< XCell > xThis( static_cast< XCell* >( this ) );
1806 sal_Int32 nRowCount = mxTable->getRowCount();
1807 sal_Int32 nColCount = mxTable->getColumnCount();
1808 for( sal_Int32 nRow = 0; nRow < nRowCount; nRow++ )
1810 for( sal_Int32 nCol = 0; nCol < nColCount; nCol++ )
1812 Reference< XCell > xCell( mxTable->getCellByPosition( nCol, nRow ) );
1813 if( xCell == xThis )
1815 return getCellName( nCol, nRow );
1820 catch( Exception& )
1824 return sName;
1829 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */