tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / table / cell.cxx
bloba38b3e46315f614464b27b7e5a1da9d58cc015d8
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>
26 #include <com/sun/star/lang/Locale.hpp>
28 #include <comphelper/sequence.hxx>
29 #include <o3tl/any.hxx>
30 #include <svl/grabbagitem.hxx>
31 #include <svl/style.hxx>
32 #include <svl/itemset.hxx>
34 #include <utility>
35 #include <vcl/svapp.hxx>
36 #include <libxml/xmlwriter.h>
38 #include <sdr/properties/textproperties.hxx>
39 #include <sdr/properties/cellproperties.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 #include <svx/sdooitm.hxx>
47 #include <svx/sdtagitm.hxx>
48 #include <svx/sdmetitm.hxx>
49 #include <svx/xit.hxx>
50 #include <getallcharpropids.hxx>
51 #include "tableundo.hxx"
52 #include <cell.hxx>
53 #include <svx/unoshprp.hxx>
54 #include <svx/unoshape.hxx>
55 #include <editeng/editobj.hxx>
56 #include <editeng/borderline.hxx>
57 #include <editeng/boxitem.hxx>
58 #include <editeng/charrotateitem.hxx>
59 #include <svx/xflbstit.hxx>
60 #include <svx/xflbmtit.hxx>
61 #include <svx/xlnclit.hxx>
62 #include <svx/svdpool.hxx>
63 #include <svx/xflclit.hxx>
64 #include <comphelper/diagnose_ex.hxx>
67 using ::editeng::SvxBorderLine;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::beans;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::text;
72 using namespace ::com::sun::star::table;
73 using namespace ::com::sun::star::drawing;
74 using namespace ::com::sun::star::style;
77 static const SvxItemPropertySet* ImplGetSvxCellPropertySet()
79 // property map for an outliner text
80 static const SfxItemPropertyMapEntry aSvxCellPropertyMap[] =
82 FILL_PROPERTIES
83 // { "HasLevels", OWN_ATTR_HASLEVELS, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::READONLY, 0},
84 { u"Style"_ustr, OWN_ATTR_STYLE, cppu::UnoType< css::style::XStyle >::get(), css::beans::PropertyAttribute::MAYBEVOID, 0},
85 { UNO_NAME_TEXT_WRITINGMODE, SDRATTR_TEXTDIRECTION, cppu::UnoType<css::text::WritingMode>::get(), 0, 0},
86 { UNO_NAME_TEXT_HORZADJUST, SDRATTR_TEXT_HORZADJUST, cppu::UnoType<css::drawing::TextHorizontalAdjust>::get(), 0, 0},
87 { UNO_NAME_TEXT_LEFTDIST, SDRATTR_TEXT_LEFTDIST, cppu::UnoType<sal_Int32>::get(), 0, 0, PropertyMoreFlags::METRIC_ITEM},
88 { UNO_NAME_TEXT_LOWERDIST, SDRATTR_TEXT_LOWERDIST, cppu::UnoType<sal_Int32>::get(), 0, 0, PropertyMoreFlags::METRIC_ITEM},
89 { UNO_NAME_TEXT_RIGHTDIST, SDRATTR_TEXT_RIGHTDIST, cppu::UnoType<sal_Int32>::get(), 0, 0, PropertyMoreFlags::METRIC_ITEM},
90 { UNO_NAME_TEXT_UPPERDIST, SDRATTR_TEXT_UPPERDIST, cppu::UnoType<sal_Int32>::get(), 0, 0, PropertyMoreFlags::METRIC_ITEM},
91 { UNO_NAME_TEXT_VERTADJUST, SDRATTR_TEXT_VERTADJUST, cppu::UnoType<css::drawing::TextVerticalAdjust>::get(), 0, 0},
92 { UNO_NAME_TEXT_WORDWRAP, SDRATTR_TEXT_WORDWRAP, cppu::UnoType<bool>::get(), 0, 0},
94 { u"TableBorder"_ustr, OWN_ATTR_TABLEBORDER, cppu::UnoType<TableBorder>::get(), 0, 0 },
95 { u"TopBorder"_ustr, SDRATTR_TABLE_BORDER, cppu::UnoType<BorderLine>::get(), 0, TOP_BORDER },
96 { u"BottomBorder"_ustr, SDRATTR_TABLE_BORDER, cppu::UnoType<BorderLine>::get(), 0, BOTTOM_BORDER },
97 { u"LeftBorder"_ustr, SDRATTR_TABLE_BORDER, cppu::UnoType<BorderLine>::get(), 0, LEFT_BORDER },
98 { u"RightBorder"_ustr, SDRATTR_TABLE_BORDER, cppu::UnoType<BorderLine>::get(), 0, RIGHT_BORDER },
99 { u"RotateAngle"_ustr, SDRATTR_TABLE_TEXT_ROTATION, cppu::UnoType<sal_Int32>::get(), 0, 0 },
100 { u"CellInteropGrabBag"_ustr, SDRATTR_TABLE_CELL_GRABBAG, cppu::UnoType<css::uno::Sequence<css::beans::PropertyValue>>::get(), 0, 0 },
102 SVX_UNOEDIT_OUTLINER_PROPERTIES,
103 SVX_UNOEDIT_CHAR_PROPERTIES,
104 SVX_UNOEDIT_PARA_PROPERTIES,
107 static SvxItemPropertySet aSvxCellPropertySet( aSvxCellPropertyMap, SdrObject::GetGlobalDrawObjectItemPool() );
108 return &aSvxCellPropertySet;
111 namespace sdr::properties
114 CellTextProvider::CellTextProvider(sdr::table::CellRef xCell)
115 : m_xCell(std::move(xCell))
119 CellTextProvider::~CellTextProvider()
123 sal_Int32 CellTextProvider::getTextCount() const
125 return 1;
128 SdrText* CellTextProvider::getText(sal_Int32 nIndex) const
130 (void) nIndex;
131 assert(nIndex == 0);
132 return m_xCell.get();
135 // create a new itemset
136 SfxItemSet CellProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
138 return SfxItemSet(rPool,
140 // range from SdrAttrObj
141 svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
142 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
143 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
145 // range for SdrTableObj
146 SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST,
148 // range from SdrTextObj
149 EE_ITEMS_START, EE_ITEMS_END>);
152 const svx::ITextProvider& CellProperties::getTextProvider() const
154 return maTextProvider;
157 CellProperties::CellProperties(SdrObject& rObj, sdr::table::Cell* pCell)
158 : TextProperties(rObj)
159 , mxCell(pCell)
160 , maTextProvider(mxCell)
164 CellProperties::CellProperties(const CellProperties& rProps, SdrObject& rObj, sdr::table::Cell* pCell)
165 : TextProperties(rProps, rObj)
166 , mxCell( pCell )
167 , maTextProvider(mxCell)
171 CellProperties::~CellProperties()
175 std::unique_ptr<BaseProperties> CellProperties::Clone(SdrObject& rObj) const
177 OSL_FAIL("CellProperties::Clone(), does not work yet!");
178 return std::unique_ptr<BaseProperties>(new CellProperties(*this, rObj,nullptr));
181 void CellProperties::ForceDefaultAttributes()
183 // deliberately do not run superclass ForceDefaultAttributes, we don't want any default attributes
186 void CellProperties::ItemSetChanged(std::span< const SfxPoolItem* const > aChangedItems, sal_uInt16 nDeletedWhich, bool bAdjustTextFrameWidthAndHeight)
188 SdrTextObj& rObj = static_cast<SdrTextObj&>(GetSdrObject());
190 if( mxCell.is() )
192 std::optional<OutlinerParaObject> pParaObj = mxCell->CreateEditOutlinerParaObject();
194 if( !pParaObj && mxCell->GetOutlinerParaObject())
195 pParaObj = *mxCell->GetOutlinerParaObject();
197 if(pParaObj)
199 // handle outliner attributes
200 Outliner* pOutliner = nullptr;
202 if(mxCell->IsTextEditActive())
204 pOutliner = rObj.GetTextEditOutliner();
206 else
208 pOutliner = &rObj.ImpGetDrawOutliner();
209 pOutliner->SetText(*pParaObj);
212 sal_Int32 nParaCount(pOutliner->GetParagraphCount());
214 // if the user sets character attributes to the complete
215 // cell we want to remove all hard set character attributes
216 // with same which ids from the text
217 std::vector<sal_uInt16> aCharWhichIds(GetAllCharPropIds(aChangedItems));
219 for(sal_Int32 nPara = 0; nPara < nParaCount; nPara++)
221 SfxItemSet aSet(pOutliner->GetParaAttribs(nPara));
222 for (const SfxPoolItem* pItem : aChangedItems)
223 aSet.Put(*pItem);
224 if (nDeletedWhich)
225 aSet.ClearItem(nDeletedWhich);
227 for (const auto& rWhichId : aCharWhichIds)
229 pOutliner->RemoveCharAttribs(nPara, rWhichId);
232 pOutliner->SetParaAttribs(nPara, aSet);
235 if(!mxCell->IsTextEditActive())
237 if(nParaCount)
239 // force ItemSet
240 GetObjectItemSet();
242 SfxItemSet aNewSet(pOutliner->GetParaAttribs(0));
243 moItemSet->Put(aNewSet);
246 std::optional<OutlinerParaObject> pTemp = pOutliner->CreateParaObject(0, nParaCount);
247 pOutliner->Clear();
248 mxCell->SetOutlinerParaObject(std::move(pTemp));
254 // call parent
255 AttributeProperties::ItemSetChanged(aChangedItems, nDeletedWhich, bAdjustTextFrameWidthAndHeight);
257 if( mxCell.is() )
258 mxCell->notifyModified();
261 void CellProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
263 if(pNewItem && (SDRATTR_TEXTDIRECTION == nWhich))
265 bool bVertical(css::text::WritingMode_TB_RL == static_cast<const SvxWritingModeItem*>(pNewItem)->GetValue());
267 sdr::table::SdrTableObj& rObj = static_cast<sdr::table::SdrTableObj&>(GetSdrObject());
268 rObj.SetVerticalWriting(bVertical);
270 // Set a cell vertical property
271 std::optional<OutlinerParaObject> pEditParaObj = mxCell->CreateEditOutlinerParaObject();
273 if( !pEditParaObj && mxCell->GetOutlinerParaObject() )
275 OutlinerParaObject* pParaObj = mxCell->GetOutlinerParaObject();
276 if(pParaObj)
277 pParaObj->SetVertical(bVertical);
281 if (pNewItem && (SDRATTR_TABLE_TEXT_ROTATION == nWhich))
283 const SvxTextRotateItem* pRotateItem = static_cast<const SvxTextRotateItem*>(pNewItem);
285 // Set a cell vertical property
286 std::optional<OutlinerParaObject> pEditParaObj = mxCell->CreateEditOutlinerParaObject();
288 if (!pEditParaObj && mxCell->GetOutlinerParaObject())
290 OutlinerParaObject* pParaObj = mxCell->GetOutlinerParaObject();
291 if (pParaObj)
293 if(pRotateItem->IsVertical() && pRotateItem->IsTopToBottom())
294 pParaObj->SetRotation(TextRotation::TOPTOBOTTOM);
295 else if (pRotateItem->IsVertical())
296 pParaObj->SetRotation(TextRotation::BOTTOMTOTOP);
297 else
298 pParaObj->SetRotation(TextRotation::NONE);
302 // Change autogrow direction
303 SdrTextObj& rObj = static_cast<SdrTextObj&>(GetSdrObject());
305 // rescue object size
306 tools::Rectangle aObjectRect = rObj.GetSnapRect();
308 const SfxItemSet& rSet = rObj.GetObjectItemSet();
309 bool bAutoGrowWidth = rSet.Get(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue();
310 bool bAutoGrowHeight = rSet.Get(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue();
312 // prepare ItemSet to set exchanged width and height items
313 SfxItemSetFixed<SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWHEIGHT> aNewSet(*rSet.GetPool());
315 aNewSet.Put(rSet);
316 aNewSet.Put(makeSdrTextAutoGrowWidthItem(bAutoGrowHeight));
317 aNewSet.Put(makeSdrTextAutoGrowHeightItem(bAutoGrowWidth));
318 rObj.SetObjectItemSet(aNewSet);
320 // restore object size
321 rObj.SetSnapRect(aObjectRect);
324 // call parent
325 AttributeProperties::ItemChange( nWhich, pNewItem );
328 } // end of namespace sdr::properties
330 namespace sdr::table {
333 // Cell
336 rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj )
338 rtl::Reference< Cell > xCell( new Cell( rTableObj ) );
339 if( xCell->mxTable.is() )
341 xCell->mxTable->addEventListener( xCell );
343 return xCell;
347 Cell::Cell(
348 SdrTableObj& rTableObj)
349 : SdrText(rTableObj)
350 ,SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
351 ,mpPropSet( ImplGetSvxCellPropertySet() )
352 ,mpProperties( new sdr::properties::CellProperties( rTableObj, this ) )
353 ,mnCellContentType( CellContentType_EMPTY )
354 ,mfValue( 0.0 )
355 ,mnError( 0 )
356 ,mbMerged( false )
357 ,mnRowSpan( 1 )
358 ,mnColSpan( 1 )
359 ,mxTable( rTableObj.getTable() )
361 // Caution: Old SetModel() indirectly did a very necessary thing here,
362 // it created a valid SvxTextEditSource which is needed to bind contained
363 // Text to the UNO API and thus to save/load and more. Added version without
364 // model change.
365 // Also done was (not needed, for reference):
366 // SetStyleSheet( nullptr, true );
367 // ForceOutlinerParaObject( OutlinerMode::TextObject );
368 if(nullptr == GetEditSource())
370 SetEditSource(new SvxTextEditSource(&GetObject(), this));
374 Cell::~Cell() COVERITY_NOEXCEPT_FALSE
376 dispose();
379 void Cell::dispose()
381 if( mxTable.is() )
385 Reference< XEventListener > xThis( this );
386 mxTable->removeEventListener( xThis );
388 catch( Exception& )
390 TOOLS_WARN_EXCEPTION("svx.table", "");
392 mxTable.clear();
395 // tdf#118199 avoid double dispose, detect by using mpProperties
396 // as indicator. Only use SetOutlinerParaObject once
397 if( mpProperties )
399 mpProperties.reset();
400 SetOutlinerParaObject( std::nullopt );
404 void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
406 if ((mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || mbMerged)
408 mnColSpan = nColumnSpan;
409 mnRowSpan = nRowSpan;
410 mbMerged = false;
411 notifyModified();
416 void Cell::mergeContent( const CellRef& xSourceCell )
418 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
420 if( !xSourceCell->hasText() )
421 return;
423 SdrOutliner& rOutliner=rTableObj.ImpGetDrawOutliner();
424 rOutliner.SetUpdateLayout(true);
426 if( hasText() )
428 rOutliner.SetText(*GetOutlinerParaObject());
429 rOutliner.AddText(*xSourceCell->GetOutlinerParaObject());
431 else
433 rOutliner.SetText(*xSourceCell->GetOutlinerParaObject());
436 SetOutlinerParaObject( rOutliner.CreateParaObject() );
437 rOutliner.Clear();
438 xSourceCell->SetOutlinerParaObject(rOutliner.CreateParaObject());
439 rOutliner.Clear();
440 SetStyleSheet( GetStyleSheet(), true );
444 void Cell::cloneFrom( const CellRef& xCell )
446 if( xCell.is() )
448 replaceContentAndFormatting( xCell );
450 mnCellContentType = xCell->mnCellContentType;
452 msFormula = xCell->msFormula;
453 mfValue = xCell->mfValue;
454 mnError = xCell->mnError;
456 mbMerged = xCell->mbMerged;
457 mnRowSpan = xCell->mnRowSpan;
458 mnColSpan = xCell->mnColSpan;
461 notifyModified();
464 void Cell::replaceContentAndFormatting( const CellRef& xSourceCell )
466 if( !(xSourceCell.is() && mpProperties) )
467 return;
469 mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );
471 // tdf#118354 OutlinerParaObject may be nullptr, do not dereference when
472 // not set (!)
473 if(xSourceCell->GetOutlinerParaObject())
475 SetOutlinerParaObject( *xSourceCell->GetOutlinerParaObject() );
478 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
479 SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );
481 if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject())
483 // TTTT should not happen - if, then a clone may be needed
484 // Maybe add an assertion here later
485 SetStyleSheet( nullptr, true );
490 void Cell::setMerged()
492 if( !mbMerged )
494 mbMerged = true;
495 notifyModified();
500 void Cell::copyFormatFrom( const CellRef& xSourceCell )
502 if( !(xSourceCell.is() && mpProperties) )
503 return;
505 mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );
506 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
507 SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );
509 if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject())
511 // TTTT should not happen - if, then a clone may be needed
512 // Maybe add an assertion here later
513 SetStyleSheet( nullptr, true );
516 notifyModified();
520 void Cell::notifyModified()
522 if( mxTable.is() )
523 mxTable->setModified( true );
527 // SdrTextShape proxy
530 bool Cell::IsActiveCell() const
532 bool isActive = false;
533 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
534 if( rTableObj.getActiveCell().get() == this )
535 isActive = true;
537 return isActive;
540 bool Cell::IsTextEditActive() const
542 bool isActive = false;
543 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
544 if(rTableObj.getActiveCell().get() == this )
546 if( rTableObj.CanCreateEditOutlinerParaObject() )
548 isActive = true;
551 return isActive;
555 bool Cell::hasText() const
557 const OutlinerParaObject* pParaObj = GetOutlinerParaObject();
558 if( pParaObj )
560 const EditTextObject& rTextObj = pParaObj->GetTextObject();
561 if( rTextObj.GetParagraphCount() >= 1 )
563 if( rTextObj.GetParagraphCount() == 1 )
565 if( !rTextObj.HasText(0) )
566 return false;
568 return true;
572 return false;
575 bool Cell::CanCreateEditOutlinerParaObject() const
577 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
578 if( rTableObj.getActiveCell().get() == this )
579 return rTableObj.CanCreateEditOutlinerParaObject();
580 return false;
583 std::optional<OutlinerParaObject> Cell::CreateEditOutlinerParaObject() const
585 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
586 if( rTableObj.getActiveCell().get() == this )
587 return rTableObj.CreateEditOutlinerParaObject();
588 return std::nullopt;
592 void Cell::SetStyleSheet( SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr )
594 // only allow cell styles for cells
595 if( pStyleSheet && pStyleSheet->GetFamily() != SfxStyleFamily::Frame )
596 return;
598 if( mpProperties && (mpProperties->GetStyleSheet() != pStyleSheet) )
600 mpProperties->SetStyleSheet( pStyleSheet, bDontRemoveHardAttr, true );
605 const SfxItemSet& Cell::GetObjectItemSet()
607 if( mpProperties )
609 return mpProperties->GetObjectItemSet();
611 else
613 OSL_FAIL("Cell::GetObjectItemSet(), called without properties!");
614 return GetObject().GetObjectItemSet();
618 void Cell::SetObjectItem(const SfxPoolItem& rItem)
620 if( mpProperties )
622 mpProperties->SetObjectItem( rItem );
623 notifyModified();
627 void Cell::SetMergedItem(const SfxPoolItem& rItem)
629 SetObjectItem(rItem);
632 SfxStyleSheet* Cell::GetStyleSheet() const
634 if( mpProperties )
635 return mpProperties->GetStyleSheet();
636 else
637 return nullptr;
640 void Cell::TakeTextAnchorRect(tools::Rectangle& rAnchorRect) const
642 rAnchorRect.SetLeft( maCellRect.Left() + GetTextLeftDistance() );
643 rAnchorRect.SetRight( maCellRect.Right() - GetTextRightDistance() );
644 rAnchorRect.SetTop( maCellRect.Top() + GetTextUpperDistance() );
645 rAnchorRect.SetBottom( maCellRect.Bottom() - GetTextLowerDistance() );
649 void Cell::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, bool bClearAllItems)
651 if( mpProperties )
653 mpProperties->SetMergedItemSetAndBroadcast(rSet, bClearAllItems);
654 notifyModified();
659 sal_Int32 Cell::calcPreferredWidth( const Size aSize )
661 if ( !hasText() )
662 return getMinimumWidth();
664 Outliner& rOutliner=static_cast< SdrTableObj& >( GetObject() ).ImpGetDrawOutliner();
665 rOutliner.SetPaperSize(aSize);
666 rOutliner.SetUpdateLayout(true);
667 ForceOutlinerParaObject( OutlinerMode::TextObject );
669 if( GetOutlinerParaObject() )
670 rOutliner.SetText(*GetOutlinerParaObject());
672 sal_Int32 nPreferredWidth = const_cast<EditEngine&>(rOutliner.GetEditEngine()).CalcTextWidth();
673 rOutliner.Clear();
675 return GetTextLeftDistance() + GetTextRightDistance() + nPreferredWidth;
678 sal_Int32 Cell::getMinimumWidth() const
680 return GetTextLeftDistance() + GetTextRightDistance() + 100;
684 sal_Int32 Cell::getMinimumHeight()
686 if( !mpProperties )
687 return 0;
689 SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
690 sal_Int32 nMinimumHeight = 0;
692 tools::Rectangle aTextRect;
693 TakeTextAnchorRect( aTextRect );
694 Size aSize( aTextRect.GetSize() );
695 aSize.setHeight(0x0FFFFFFF );
697 SdrOutliner* pEditOutliner = rTableObj.GetCellTextEditOutliner( *this );
698 if(pEditOutliner)
700 pEditOutliner->SetMaxAutoPaperSize(aSize);
701 nMinimumHeight = pEditOutliner->GetTextHeight()+1;
703 else
705 Outliner& rOutliner=rTableObj.ImpGetDrawOutliner();
706 rOutliner.SetPaperSize(aSize);
707 rOutliner.SetUpdateLayout(true);
708 ForceOutlinerParaObject( OutlinerMode::TextObject );
710 if( GetOutlinerParaObject() )
712 rOutliner.SetText(*GetOutlinerParaObject());
714 nMinimumHeight=rOutliner.GetTextHeight()+1;
715 rOutliner.Clear();
718 nMinimumHeight += GetTextUpperDistance() + GetTextLowerDistance();
719 return nMinimumHeight;
723 tools::Long Cell::GetTextLeftDistance() const
725 return GetItemSet().Get(SDRATTR_TEXT_LEFTDIST).GetValue();
729 tools::Long Cell::GetTextRightDistance() const
731 return GetItemSet().Get(SDRATTR_TEXT_RIGHTDIST).GetValue();
735 tools::Long Cell::GetTextUpperDistance() const
737 return GetItemSet().Get(SDRATTR_TEXT_UPPERDIST).GetValue();
741 tools::Long Cell::GetTextLowerDistance() const
743 return GetItemSet().Get(SDRATTR_TEXT_LOWERDIST).GetValue();
747 SdrTextVertAdjust Cell::GetTextVerticalAdjust() const
749 return GetItemSet().Get(SDRATTR_TEXT_VERTADJUST).GetValue();
753 SdrTextHorzAdjust Cell::GetTextHorizontalAdjust() const
755 return GetItemSet().Get(SDRATTR_TEXT_HORZADJUST).GetValue();
759 void Cell::SetOutlinerParaObject( std::optional<OutlinerParaObject> pTextObject )
761 bool bNullTextObject = !pTextObject;
762 SdrText::SetOutlinerParaObject( std::move(pTextObject) );
763 maSelection.start.nPara = EE_PARA_MAX;
765 if( bNullTextObject )
766 ForceOutlinerParaObject( OutlinerMode::TextObject );
770 void Cell::AddUndo()
772 SdrObject& rObj = GetObject();
774 if( rObj.IsInserted() && rObj.getSdrModelFromSdrObject().IsUndoEnabled() )
776 CellRef xCell( this );
777 rObj.getSdrModelFromSdrObject().AddUndo( std::make_unique<CellUndo>( &rObj, xCell ) );
779 // Undo action for the after-text-edit-ended stack.
780 SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(&rObj);
781 if (pTableObj && pTableObj->IsTextEditActive())
782 pTableObj->AddUndo(new CellUndo(pTableObj, xCell));
786 sdr::properties::CellProperties* Cell::CloneProperties( SdrObject& rNewObj, Cell& rNewCell )
788 if (!mpProperties)
789 return nullptr;
790 return new sdr::properties::CellProperties( *mpProperties, rNewObj, &rNewCell );
794 // XInterface
797 Any SAL_CALL Cell::queryInterface( const Type & rType )
799 if( rType == cppu::UnoType<XMergeableCell>::get() )
800 return Any( Reference< XMergeableCell >( this ) );
802 if( rType == cppu::UnoType<XCell>::get() )
803 return Any( Reference< XCell >( this ) );
805 if( rType == cppu::UnoType<XLayoutConstrains>::get() )
806 return Any( Reference< XLayoutConstrains >( this ) );
808 if( rType == cppu::UnoType<XEventListener>::get() )
809 return Any( Reference< XEventListener >( this ) );
811 Any aRet( SvxUnoTextBase::queryAggregation( rType ) );
812 if( aRet.hasValue() )
813 return aRet;
815 return ::cppu::OWeakObject::queryInterface( rType );
819 void SAL_CALL Cell::acquire() noexcept
821 SdrText::acquire();
825 void SAL_CALL Cell::release() noexcept
827 SdrText::release();
831 // XTypeProvider
834 Sequence< Type > SAL_CALL Cell::getTypes( )
836 return comphelper::concatSequences( SvxUnoTextBase::getTypes(),
837 std::initializer_list<Type>{
838 cppu::UnoType<XMergeableCell>::get(),
839 cppu::UnoType<XLayoutConstrains>::get() });
843 Sequence< sal_Int8 > SAL_CALL Cell::getImplementationId( )
845 return css::uno::Sequence<sal_Int8>();
848 // XLayoutConstrains
849 css::awt::Size SAL_CALL Cell::getMinimumSize()
851 return css::awt::Size( getMinimumWidth(), getMinimumHeight() );
855 css::awt::Size SAL_CALL Cell::getPreferredSize()
857 return getMinimumSize();
861 css::awt::Size SAL_CALL Cell::calcAdjustedSize( const css::awt::Size& aNewSize )
863 return aNewSize;
867 // XMergeableCell
870 sal_Int32 SAL_CALL Cell::getRowSpan()
872 return mnRowSpan;
876 sal_Int32 SAL_CALL Cell::getColumnSpan()
878 return mnColSpan;
882 sal_Bool SAL_CALL Cell::isMerged()
884 return mbMerged;
888 // XCell
891 OUString SAL_CALL Cell::getFormula( )
893 return msFormula;
897 void SAL_CALL Cell::setFormula( const OUString& aFormula )
899 if( msFormula != aFormula )
901 msFormula = aFormula;
906 double SAL_CALL Cell::getValue( )
908 return mfValue;
912 void SAL_CALL Cell::setValue( double nValue )
914 if( mfValue != nValue )
916 mfValue = nValue;
917 mnCellContentType = CellContentType_VALUE;
922 CellContentType SAL_CALL Cell::getType()
924 return mnCellContentType;
928 sal_Int32 SAL_CALL Cell::getError( )
930 return mnError;
934 // XPropertySet
937 Any Cell::GetAnyForItem( SfxItemSet const & aSet, const SfxItemPropertyMapEntry* pMap )
939 Any aAny( SvxItemPropertySet_getPropertyValue( pMap, aSet ) );
941 if( pMap->aType != aAny.getValueType() )
943 // since the sfx uint16 item now exports a sal_Int32, we may have to fix this here
944 if( ( pMap->aType == ::cppu::UnoType<sal_Int16>::get()) && aAny.getValueType() == ::cppu::UnoType<sal_Int32>::get() )
946 sal_Int32 nValue = 0;
947 aAny >>= nValue;
948 aAny <<= static_cast<sal_Int16>(nValue);
950 else
952 OSL_FAIL("GetAnyForItem() Returnvalue has wrong Type!" );
956 return aAny;
959 Reference< XPropertySetInfo > SAL_CALL Cell::getPropertySetInfo()
961 return mpPropSet->getPropertySetInfo();
965 void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
967 ::SolarMutexGuard aGuard;
969 if(mpProperties == nullptr)
970 throw DisposedException();
972 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName);
973 if( pMap )
975 if( (pMap->nFlags & PropertyAttribute::READONLY ) != 0 )
976 throw PropertyVetoException();
978 switch( pMap->nWID )
980 case OWN_ATTR_STYLE:
982 Reference< XStyle > xStyle;
983 if( !( rValue >>= xStyle ) )
984 throw IllegalArgumentException();
986 SfxUnoStyleSheet* pStyle = SfxUnoStyleSheet::getUnoStyleSheet(xStyle);
987 SetStyleSheet( pStyle, true );
988 return;
990 case OWN_ATTR_TABLEBORDER:
992 auto pBorder = o3tl::tryAccess<TableBorder>(rValue);
993 if(!pBorder)
994 break;
996 SvxBoxItem aBox( SDRATTR_TABLE_BORDER );
997 SvxBoxInfoItem aBoxInfo( SDRATTR_TABLE_BORDER_INNER );
998 SvxBorderLine aLine;
1000 bool bSet = SvxBoxItem::LineToSvxLine(pBorder->TopLine, aLine, false);
1001 aBox.SetLine(bSet ? &aLine : nullptr, SvxBoxItemLine::TOP);
1002 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::TOP, pBorder->IsTopLineValid);
1004 bSet = SvxBoxItem::LineToSvxLine(pBorder->BottomLine, aLine, false);
1005 aBox.SetLine(bSet ? &aLine : nullptr, SvxBoxItemLine::BOTTOM);
1006 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::BOTTOM, pBorder->IsBottomLineValid);
1008 bSet = SvxBoxItem::LineToSvxLine(pBorder->LeftLine, aLine, false);
1009 aBox.SetLine(bSet ? &aLine : nullptr, SvxBoxItemLine::LEFT);
1010 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::LEFT, pBorder->IsLeftLineValid);
1012 bSet = SvxBoxItem::LineToSvxLine(pBorder->RightLine, aLine, false);
1013 aBox.SetLine(bSet ? &aLine : nullptr, SvxBoxItemLine::RIGHT);
1014 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::RIGHT, pBorder->IsRightLineValid);
1016 bSet = SvxBoxItem::LineToSvxLine(pBorder->HorizontalLine, aLine, false);
1017 aBoxInfo.SetLine(bSet ? &aLine : nullptr, SvxBoxInfoItemLine::HORI);
1018 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::HORI, pBorder->IsHorizontalLineValid);
1020 bSet = SvxBoxItem::LineToSvxLine(pBorder->VerticalLine, aLine, false);
1021 aBoxInfo.SetLine(bSet ? &aLine : nullptr, SvxBoxInfoItemLine::VERT);
1022 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::VERT, pBorder->IsVerticalLineValid);
1024 aBox.SetAllDistances(pBorder->Distance); //TODO
1025 aBoxInfo.SetValid(SvxBoxInfoItemValidFlags::DISTANCE, pBorder->IsDistanceValid);
1027 mpProperties->SetObjectItem(aBox);
1028 mpProperties->SetObjectItem(aBoxInfo);
1029 return;
1031 case OWN_ATTR_FILLBMP_MODE:
1033 BitmapMode eMode;
1034 if(!(rValue >>= eMode) )
1036 sal_Int32 nMode = 0;
1037 if(!(rValue >>= nMode))
1038 throw IllegalArgumentException();
1040 eMode = static_cast<BitmapMode>(nMode);
1043 mpProperties->SetObjectItem( XFillBmpStretchItem( eMode == BitmapMode_STRETCH ) );
1044 mpProperties->SetObjectItem( XFillBmpTileItem( eMode == BitmapMode_REPEAT ) );
1045 return;
1047 case SDRATTR_TABLE_TEXT_ROTATION:
1049 sal_Int32 nRotVal = 0;
1050 if (!(rValue >>= nRotVal))
1051 throw IllegalArgumentException();
1053 if (nRotVal != 27000 && nRotVal != 9000 && nRotVal != 0)
1054 throw IllegalArgumentException();
1056 mpProperties->SetObjectItem(SvxTextRotateItem(Degree10(nRotVal/10), SDRATTR_TABLE_TEXT_ROTATION));
1057 return;
1059 case SDRATTR_TABLE_CELL_GRABBAG:
1061 if (mpGrabBagItem == nullptr)
1062 mpGrabBagItem.reset(new SfxGrabBagItem);
1064 mpGrabBagItem->PutValue(rValue, 0);
1065 return;
1067 default:
1069 SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), pMap->nWID, pMap->nWID);
1070 aSet.Put(mpProperties->GetItem(pMap->nWID));
1072 bool bSpecial = false;
1074 switch( pMap->nWID )
1076 case XATTR_FILLBITMAP:
1077 case XATTR_FILLGRADIENT:
1078 case XATTR_FILLHATCH:
1079 case XATTR_FILLFLOATTRANSPARENCE:
1080 case XATTR_LINEEND:
1081 case XATTR_LINESTART:
1082 case XATTR_LINEDASH:
1084 if( pMap->nMemberId == MID_NAME )
1086 OUString aApiName;
1087 if( rValue >>= aApiName )
1089 if(SvxShape::SetFillAttribute(pMap->nWID, aApiName, aSet, &GetObject().getSdrModelFromSdrObject()))
1090 bSpecial = true;
1094 break;
1097 if( !bSpecial )
1100 if( !SvxUnoTextRangeBase::SetPropertyValueHelper( pMap, rValue, aSet ))
1102 if( aSet.GetItemState( pMap->nWID ) != SfxItemState::SET )
1104 // fetch the default from ItemPool
1105 if(SfxItemPool::IsWhich(pMap->nWID))
1106 aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetUserOrPoolDefaultItem(pMap->nWID));
1109 if( aSet.GetItemState( pMap->nWID ) == SfxItemState::SET )
1111 SvxItemPropertySet_setPropertyValue( pMap, rValue, aSet );
1116 GetObject().getSdrModelFromSdrObject().SetChanged();
1117 mpProperties->SetMergedItemSetAndBroadcast( aSet );
1118 return;
1122 throw UnknownPropertyException( rPropertyName, getXWeak());
1126 Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName )
1128 ::SolarMutexGuard aGuard;
1130 if(mpProperties == nullptr)
1131 throw DisposedException();
1133 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1134 if( pMap )
1136 switch( pMap->nWID )
1138 case OWN_ATTR_STYLE:
1140 return Any( Reference< XStyle >( dynamic_cast< SfxUnoStyleSheet* >( GetStyleSheet() ) ) );
1142 case OWN_ATTR_TABLEBORDER:
1144 const SvxBoxInfoItem& rBoxInfoItem = mpProperties->GetItem(SDRATTR_TABLE_BORDER_INNER);
1145 const SvxBoxItem& rBox = mpProperties->GetItem(SDRATTR_TABLE_BORDER);
1147 TableBorder aTableBorder;
1148 aTableBorder.TopLine = SvxBoxItem::SvxLineToLine(rBox.GetTop(), false);
1149 aTableBorder.IsTopLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::TOP);
1150 aTableBorder.BottomLine = SvxBoxItem::SvxLineToLine(rBox.GetBottom(), false);
1151 aTableBorder.IsBottomLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::BOTTOM);
1152 aTableBorder.LeftLine = SvxBoxItem::SvxLineToLine(rBox.GetLeft(), false);
1153 aTableBorder.IsLeftLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::LEFT);
1154 aTableBorder.RightLine = SvxBoxItem::SvxLineToLine(rBox.GetRight(), false);
1155 aTableBorder.IsRightLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::RIGHT );
1156 aTableBorder.HorizontalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetHori(), false);
1157 aTableBorder.IsHorizontalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::HORI);
1158 aTableBorder.VerticalLine = SvxBoxItem::SvxLineToLine(rBoxInfoItem.GetVert(), false);
1159 aTableBorder.IsVerticalLineValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::VERT);
1160 aTableBorder.Distance = rBox.GetSmallestDistance();
1161 aTableBorder.IsDistanceValid = rBoxInfoItem.IsValid(SvxBoxInfoItemValidFlags::DISTANCE);
1163 return Any( aTableBorder );
1165 case OWN_ATTR_FILLBMP_MODE:
1167 const XFillBmpStretchItem& rStretchItem = mpProperties->GetItem(XATTR_FILLBMP_STRETCH);
1168 const XFillBmpTileItem& rTileItem = mpProperties->GetItem(XATTR_FILLBMP_TILE);
1169 if( rTileItem.GetValue() )
1171 return Any( BitmapMode_REPEAT );
1173 else if( rStretchItem.GetValue() )
1175 return Any( BitmapMode_STRETCH );
1177 else
1179 return Any( BitmapMode_NO_REPEAT );
1182 case SDRATTR_TABLE_TEXT_ROTATION:
1184 const SvxTextRotateItem& rTextRotate = mpProperties->GetItem(SDRATTR_TABLE_TEXT_ROTATION);
1185 return Any(sal_Int32(to<Degree100>(rTextRotate.GetValue())));
1187 case SDRATTR_TABLE_CELL_GRABBAG:
1189 if (mpGrabBagItem != nullptr)
1191 Any aGrabBagSequence;
1192 mpGrabBagItem->QueryValue(aGrabBagSequence);
1193 return aGrabBagSequence;
1195 else
1196 return Any{css::uno::Sequence<css::beans::PropertyValue>()};
1198 default:
1200 SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), pMap->nWID, pMap->nWID);
1201 aSet.Put(mpProperties->GetItem(pMap->nWID));
1203 Any aAny;
1204 if(!SvxUnoTextRangeBase::GetPropertyValueHelper( aSet, pMap, aAny ))
1206 if(!aSet.Count())
1208 // fetch the default from ItemPool
1209 if(SfxItemPool::IsWhich(pMap->nWID))
1210 aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetUserOrPoolDefaultItem(pMap->nWID));
1213 if( aSet.Count() )
1214 aAny = GetAnyForItem( aSet, pMap );
1217 return aAny;
1221 throw UnknownPropertyException( PropertyName, getXWeak());
1225 void SAL_CALL Cell::addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ )
1230 void SAL_CALL Cell::removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ )
1235 void SAL_CALL Cell::addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
1240 void SAL_CALL Cell::removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
1245 // XMultiPropertySet
1248 void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyNames, const Sequence< Any >& aValues )
1250 ::SolarMutexGuard aSolarGuard;
1252 if(mpProperties == nullptr)
1253 throw DisposedException();
1255 const sal_Int32 nCount = aPropertyNames.getLength();
1256 if (nCount != aValues.getLength())
1257 throw css::lang::IllegalArgumentException(u"lengths do not match"_ustr,
1258 getXWeak(), -1);
1260 const OUString* pNames = aPropertyNames.getConstArray();
1261 const Any* pValues = aValues.getConstArray();
1263 for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++, pNames++, pValues++ )
1267 setPropertyValue( *pNames, *pValues );
1269 catch( UnknownPropertyException& )
1271 TOOLS_WARN_EXCEPTION("svx.table", "unknown property!");
1273 catch( Exception& )
1275 TOOLS_WARN_EXCEPTION("svx.table", "");
1281 Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aPropertyNames )
1283 ::SolarMutexGuard aSolarGuard;
1285 if(mpProperties == nullptr)
1286 throw DisposedException();
1288 const sal_Int32 nCount = aPropertyNames.getLength();
1289 Sequence< Any > aRet( nCount );
1290 Any* pValue = aRet.getArray();
1292 for( const OUString& rName : aPropertyNames )
1296 *pValue = getPropertyValue( rName );
1298 catch( UnknownPropertyException& )
1300 TOOLS_WARN_EXCEPTION("svx.table", "unknown property!");
1302 catch( Exception& )
1304 TOOLS_WARN_EXCEPTION("svx.table", "");
1306 pValue++;
1309 return aRet;
1313 void SAL_CALL Cell::addPropertiesChangeListener( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ )
1318 void SAL_CALL Cell::removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& /*xListener*/ )
1323 void SAL_CALL Cell::firePropertiesChangeEvent( const Sequence< OUString >& /*aPropertyNames*/, const Reference< XPropertiesChangeListener >& /*xListener*/ )
1328 // XPropertyState
1331 PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName )
1333 ::SolarMutexGuard aGuard;
1335 if(mpProperties == nullptr)
1336 throw DisposedException();
1338 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1340 if( pMap )
1342 PropertyState eState;
1343 switch( pMap->nWID )
1345 case OWN_ATTR_FILLBMP_MODE:
1347 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1349 const bool bStretch = rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SfxItemState::SET;
1350 const bool bTile = rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SfxItemState::SET;
1351 if( bStretch || bTile )
1353 eState = PropertyState_DIRECT_VALUE;
1355 else
1357 eState = PropertyState_DEFAULT_VALUE;
1359 break;
1361 case OWN_ATTR_STYLE:
1363 return PropertyState_DIRECT_VALUE;
1365 case OWN_ATTR_TABLEBORDER:
1367 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1368 if( (rSet.GetItemState( SDRATTR_TABLE_BORDER_INNER, false ) == SfxItemState::DEFAULT) && (rSet.GetItemState( SDRATTR_TABLE_BORDER, false ) == SfxItemState::DEFAULT) )
1369 return PropertyState_DEFAULT_VALUE;
1371 return PropertyState_DIRECT_VALUE;
1373 default:
1375 const SfxItemSet& rSet = mpProperties->GetMergedItemSet();
1377 switch( rSet.GetItemState( pMap->nWID, false ) )
1379 case SfxItemState::SET:
1380 eState = PropertyState_DIRECT_VALUE;
1381 break;
1382 case SfxItemState::DEFAULT:
1383 eState = PropertyState_DEFAULT_VALUE;
1384 break;
1385 default:
1386 eState = PropertyState_AMBIGUOUS_VALUE;
1387 break;
1390 // if an item is set, this doesn't mean we want it :)
1391 if( PropertyState_DIRECT_VALUE == eState )
1393 switch( pMap->nWID )
1395 // the following items are disabled by changing the
1396 // fill style or the line style. so there is no need
1397 // to export items without names which should be empty
1398 case XATTR_FILLBITMAP:
1399 case XATTR_FILLGRADIENT:
1400 case XATTR_FILLHATCH:
1401 case XATTR_LINEDASH:
1403 const NameOrIndex* pItem = rSet.GetItem<NameOrIndex>(pMap->nWID);
1404 if( ( pItem == nullptr ) || pItem->GetName().isEmpty() )
1405 eState = PropertyState_DEFAULT_VALUE;
1407 break;
1409 // #i36115#
1410 // If e.g. the LineStart is on NONE and thus the string has length 0, it still
1411 // may be a hard attribute covering the set LineStart of the parent (Style).
1412 // #i37644#
1413 // same is for fill float transparency
1414 case XATTR_LINEEND:
1415 case XATTR_LINESTART:
1416 case XATTR_FILLFLOATTRANSPARENCE:
1418 const NameOrIndex* pItem = rSet.GetItem<NameOrIndex>(pMap->nWID);
1419 if( pItem == nullptr )
1420 eState = PropertyState_DEFAULT_VALUE;
1422 break;
1423 case XATTR_FILLCOLOR:
1424 if (pMap->nMemberId == MID_COLOR_THEME_INDEX)
1426 auto const* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID);
1427 if (!pColor->getComplexColor().isValidThemeType())
1429 eState = PropertyState_DEFAULT_VALUE;
1432 else if (pMap->nMemberId == MID_COLOR_LUM_MOD)
1434 auto const* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID);
1435 sal_Int16 nLumMod = 10000;
1436 for (auto const& rTransform : pColor->getComplexColor().getTransformations())
1438 if (rTransform.meType == model::TransformationType::LumMod)
1439 nLumMod = rTransform.mnValue;
1441 if (nLumMod == 10000)
1443 eState = PropertyState_DEFAULT_VALUE;
1446 else if (pMap->nMemberId == MID_COLOR_LUM_OFF)
1448 auto const* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID);
1449 sal_Int16 nLumOff = 0;
1450 for (auto const& rTransform : pColor->getComplexColor().getTransformations())
1452 if (rTransform.meType == model::TransformationType::LumOff)
1453 nLumOff = rTransform.mnValue;
1455 if (nLumOff == 0)
1457 eState = PropertyState_DEFAULT_VALUE;
1460 else if (pMap->nMemberId == MID_COMPLEX_COLOR)
1462 auto const* pColor = rSet.GetItem<XFillColorItem>(pMap->nWID);
1463 if (pColor->getComplexColor().getType() == model::ColorType::Unused)
1465 eState = PropertyState_DEFAULT_VALUE;
1468 break;
1469 case XATTR_LINECOLOR:
1470 if (pMap->nMemberId == MID_COMPLEX_COLOR)
1472 auto const* pColor = rSet.GetItem<XLineColorItem>(pMap->nWID);
1473 if (pColor->getComplexColor().getType() == model::ColorType::Unused)
1475 eState = PropertyState_DEFAULT_VALUE;
1478 break;
1483 return eState;
1485 throw UnknownPropertyException(PropertyName);
1489 Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUString >& aPropertyName )
1491 ::SolarMutexGuard aGuard;
1493 if(mpProperties == nullptr)
1494 throw DisposedException();
1496 const sal_Int32 nCount = aPropertyName.getLength();
1497 Sequence< PropertyState > aRet( nCount );
1499 std::transform(aPropertyName.begin(), aPropertyName.end(), aRet.getArray(),
1500 [this](const OUString& rName) -> PropertyState {
1503 return getPropertyState( rName );
1505 catch( Exception& )
1507 return PropertyState_AMBIGUOUS_VALUE;
1511 return aRet;
1515 void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName )
1517 ::SolarMutexGuard aGuard;
1519 if(mpProperties == nullptr)
1520 throw DisposedException();
1522 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
1523 if( pMap )
1525 switch( pMap->nWID )
1527 case OWN_ATTR_FILLBMP_MODE:
1529 mpProperties->ClearObjectItem( XATTR_FILLBMP_STRETCH );
1530 mpProperties->ClearObjectItem( XATTR_FILLBMP_TILE );
1531 break;
1533 case OWN_ATTR_STYLE:
1534 break;
1536 case OWN_ATTR_TABLEBORDER:
1538 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER_INNER );
1539 mpProperties->ClearObjectItem( SDRATTR_TABLE_BORDER );
1540 break;
1543 default:
1545 mpProperties->ClearObjectItem( pMap->nWID );
1549 GetObject().getSdrModelFromSdrObject().SetChanged();
1550 return;
1552 throw UnknownPropertyException( PropertyName, getXWeak());
1556 Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName )
1558 ::SolarMutexGuard aGuard;
1560 if(mpProperties == nullptr)
1561 throw DisposedException();
1563 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName);
1564 if( pMap )
1566 switch( pMap->nWID )
1568 case OWN_ATTR_FILLBMP_MODE:
1569 return Any( BitmapMode_NO_REPEAT );
1571 case OWN_ATTR_STYLE:
1573 Reference< XStyle > xStyle;
1574 return Any( xStyle );
1577 case OWN_ATTR_TABLEBORDER:
1579 TableBorder aBorder;
1580 return Any( aBorder );
1583 default:
1585 if( SfxItemPool::IsWhich(pMap->nWID) )
1587 SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), pMap->nWID, pMap->nWID);
1588 aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetUserOrPoolDefaultItem(pMap->nWID));
1589 return GetAnyForItem( aSet, pMap );
1594 throw UnknownPropertyException( aPropertyName, getXWeak());
1598 // XMultiPropertyStates
1601 void SAL_CALL Cell::setAllPropertiesToDefault()
1603 mpProperties.reset(new sdr::properties::CellProperties( static_cast< SdrTableObj& >( GetObject() ), this ));
1605 SdrOutliner& rOutliner = GetObject().ImpGetDrawOutliner();
1607 OutlinerParaObject* pParaObj = GetOutlinerParaObject();
1608 if( !pParaObj )
1609 return;
1611 rOutliner.SetText(*pParaObj);
1612 sal_Int32 nParaCount(rOutliner.GetParagraphCount());
1614 if(nParaCount)
1616 auto aSelection = ESelection::All();
1617 rOutliner.RemoveAttribs(aSelection, true, 0);
1619 std::optional<OutlinerParaObject> pTemp = rOutliner.CreateParaObject(0, nParaCount);
1620 rOutliner.Clear();
1622 SetOutlinerParaObject(std::move(pTemp));
1627 void SAL_CALL Cell::setPropertiesToDefault( const Sequence< OUString >& aPropertyNames )
1629 for(const OUString& rName : aPropertyNames)
1630 setPropertyToDefault( rName );
1634 Sequence< Any > SAL_CALL Cell::getPropertyDefaults( const Sequence< OUString >& aPropertyNames )
1636 sal_Int32 nCount = aPropertyNames.getLength();
1637 Sequence< Any > aDefaults( nCount );
1639 std::transform(aPropertyNames.begin(), aPropertyNames.end(), aDefaults.getArray(),
1640 [this](const OUString& rName) -> Any { return getPropertyDefault(rName); });
1642 return aDefaults;
1646 // XText
1649 void SAL_CALL Cell::insertTextContent( const Reference< XTextRange >& xRange, const Reference< XTextContent >& xContent, sal_Bool bAbsorb )
1651 SvxUnoTextBase::insertTextContent( xRange, xContent, bAbsorb );
1652 notifyModified();
1656 void SAL_CALL Cell::removeTextContent( const Reference< XTextContent >& xContent )
1658 SvxUnoTextBase::removeTextContent( xContent );
1659 notifyModified();
1663 // XSimpleText
1666 void SAL_CALL Cell::insertString( const Reference< XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb )
1668 SvxUnoTextBase::insertString( xRange, aString, bAbsorb );
1669 notifyModified();
1673 void SAL_CALL Cell::insertControlCharacter( const Reference< XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1675 SvxUnoTextBase::insertControlCharacter( xRange, nControlCharacter, bAbsorb );
1676 notifyModified();
1680 // XTextRange
1683 OUString SAL_CALL Cell::getString( )
1685 maSelection.start.nPara = EE_PARA_MAX;
1686 return SvxUnoTextBase::getString();
1690 void SAL_CALL Cell::setString( const OUString& aString )
1692 SvxUnoTextBase::setString( aString );
1693 notifyModified();
1696 // XEventListener
1697 void SAL_CALL Cell::disposing( const EventObject& /*Source*/ )
1699 mxTable.clear();
1700 dispose();
1703 void Cell::dumpAsXml(xmlTextWriterPtr pWriter, sal_Int32 nRow, sal_Int32 nCol) const
1705 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Cell"));
1706 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("row"), "%" SAL_PRIdINT32, nRow);
1707 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("col"), "%" SAL_PRIdINT32, nCol);
1708 SdrText::dumpAsXml(pWriter);
1709 //SvxUnoTextBase::dumpAsXml(pWriter);
1710 //mpPropSet->dumpAsXml(pWriter);
1711 mpProperties->dumpAsXml(pWriter);
1712 (void)xmlTextWriterEndElement(pWriter);
1717 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */