24 #include <com/sun/star/table/XTable.hpp>
25 #include <com/sun/star/table/XMergeableCellRange.hpp>
37 #include <editeng/editeng.hxx>
40 #include <editeng/editids.hrc>
62 explicit RTFCellDefault(
SfxItemPool* pPool ) : maItemSet( *pPool ), mnRowSpan(1), mnColSpan(1), mnCellX(0) {}
80 explicit RTFCellInfo(
SfxItemPool& rPool ) : maItemSet( rPool ), mnStartPara(0), mnParaCount(0), mnCellX(0), mnRowSpan(1) {}
129 std::vector< RTFColumnVectorPtr >
maRows;
144 : mrTableObj( rTableObj )
146 , mrItemPool( rTableObj.getSdrModelFromSdrObject().GetItemPool() )
153 , mpActDefault( nullptr )
154 , mpDefMerge( nullptr )
155 , mxTable( rTableObj.getTable() )
168 mpOutliner->Read( rStream, OUString(), EETextFormat::Rtf );
176 switch ( rInfo.eState )
178 case RtfImportState::NextToken:
181 case RtfImportState::UnknownAttr:
184 case RtfImportState::Start:
191 case RtfImportState::End:
192 if ( rInfo.aSelection.nEndPos )
194 mpActDefault =
nullptr;
196 rInfo.aSelection.nEndPara++;
200 case RtfImportState::SetAttr:
201 case RtfImportState::InsertText:
202 case RtfImportState::InsertPara:
205 SAL_WARN(
"svx.table",
"unknown ImportInfo.eState");
219 RTFCellInfoPtr xCellInfo = std::make_shared<RTFCellInfo>(
mrItemPool);
234 if ( xCellInfo->mnRowSpan == 0 &&
mnVMergeIdx < nSize )
237 if (xLastCell->mnRowSpan)
238 xCellInfo->mxVMergeCell = xLastCell;
240 xCellInfo->mxVMergeCell = xLastCell->mxVMergeCell;
247 if ( xCellInfo->mxVMergeCell )
250 xColumn->back()->mxVMergeCell != xCellInfo->mxVMergeCell )
251 xCellInfo->mxVMergeCell->mnRowSpan++;
254 xColumn->push_back( xCellInfo );
264 if ( aNextEdge ==
maColumnEdges.end() || nEdge != *aNextEdge )
275 sal_Int32 nColCount =
mxTable->getColumnCount();
276 Reference< XTableColumns > xCols(
mxTable->getColumns(), UNO_SET_THROW );
278 if( nColCount < nColMax )
280 xCols->insertByIndex( nColCount, nColMax - nColCount );
281 nColCount =
mxTable->getColumnCount();
284 static const OUStringLiteral sWidth(
u"Width");
285 sal_Int32 nCol, nLastEdge = 0;
286 for( nCol = 0; nCol < nColCount; nCol++ )
291 xSet->setPropertyValue( sWidth,
Any( nWidth ) );
295 const sal_Int32 nRowCount =
mxTable->getRowCount();
298 Reference< XTableRows > xRows(
mxTable->getRows(), UNO_SET_THROW );
299 xRows->insertByIndex( nRowCount,
mnRowCnt - nRowCount );
302 for( sal_Int32 nRow = 0; nRow < static_cast<sal_Int32>(
maRows.size()); nRow++ )
307 for( sal_Int32 nIdx = 0; nCol < nColMax && nIdx < static_cast<sal_Int32>(xColumn->size()); nIdx++ )
309 RTFCellInfoPtr xCellInfo( (*xColumn)[nIdx] );
311 CellRef xCell( dynamic_cast< Cell* >(
mxTable->getCellByPosition( nCol, nRow ).get() ) );
312 if( xCell.is() && xCellInfo )
315 if( xCellInfo->maItemSet.GetItemState(
SDRATTR_TABLE_BORDER,
false,&pPoolItem)==SfxItemState::SET)
316 xCell->SetMergedItem( *pPoolItem );
323 rOutliner.
SetText( *pTextObject );
327 sal_Int32 nLastRow = nRow;
328 if ( xCellInfo->mnRowSpan )
329 nLastRow += xCellInfo->mnRowSpan - 1;
331 aEdge = std::lower_bound( aEdge,
maColumnEdges.end(), xCellInfo->mnCellX );
332 sal_Int32 nLastCol = nCol;
339 if ( nLastCol > nCol || nLastRow > nRow )
341 Reference< XMergeableCellRange > xRange(
mxTable->createCursorByRange(
mxTable->getCellRangeByPosition( nCol, nRow, nLastCol, nLastRow ) ), UNO_QUERY_THROW );
342 if( xRange->isMergeable() )
351 aRect.
SetRight( aRect.Left() + nLastEdge );
367 maRows.push_back( std::make_shared<std::vector<std::shared_ptr<RTFCellInfo>>>( ) );
429 std::shared_ptr<RTFCellDefault> pDefault(
mpInsDefault.release() );
437 pDefault->mnCellX = nSize;
498 aParser.
Read( rStream );
#define LINK(Instance, Class, Member)
void SetRtfImportHdl(const Link< RtfImportInfo &, void > &rLink)
Reference< XTable > mxTable
std::shared_ptr< RTFCellInfo > mxVMergeCell
std::unique_ptr< SdrOutliner > mpOutliner
std::vector< sal_Int32 >::iterator maLastEdge
std::shared_ptr< RTFCellInfo > RTFCellInfoPtr
void SetAttrPool(SfxItemPool *pNewPool)
constexpr auto convertTwipToMm100(N n)
RTFCellDefaultVector maDefaultList
virtual const tools::Rectangle & GetSnapRect() const override
virtual void NbcSetSnapRect(const tools::Rectangle &rRect) override
SfxStyleSheet * GetStyleSheet() const
std::shared_ptr< RTFColumnVector > RTFColumnVectorPtr
IMPL_LINK(SdrTableRTFParser, RTFImportHdl, RtfImportInfo &, rInfo, void)
RTFColumnVectorPtr mxLastRow
RTFCellDefault * mpDefMerge
void InsertCell(RtfImportInfo const *pInfo)
void Read(SvStream &rStream)
void NbcSetOutlinerParaObjectForText(std::optional< OutlinerParaObject > pTextObject, SdrText *pText)
SdrTableRTFParser & operator=(const SdrTableRTFParser &)=delete
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetText(const OutlinerParaObject &)
#define DBG_ASSERT(sCon, aError)
std::vector< std::shared_ptr< RTFCellDefault > > RTFCellDefaultVector
const Link< RtfImportInfo &, void > & GetRtfImportHdl() const
void SetPardMap(sal_uInt16 wid, sal_uInt16 widTrue)
std::optional< OutlinerParaObject > CreateParaObject(sal_Int32 nStartPara=0, sal_Int32 nParaCount=EE_PARA_ALL) const
SvParser< int > * pParser
RTFCellDefaultVector::iterator maDefaultIterator
std::vector< RTFColumnVectorPtr > maRows
constexpr TypedWhichId< SvxBoxItem > SDRATTR_TABLE_BORDER(SDRATTR_TABLE_FIRST+0)
RTFCellDefault * mpActDefault
std::unique_ptr< RTFCellDefault > mpInsDefault
SdrTableRTFParser(SdrTableObj &rTableObj)
std::unique_ptr< SdrOutliner > SdrMakeOutliner(OutlinerMode nOutlinerMode, SdrModel &rModel)
Create an Outliner with the engine-global default settings on the heap.
std::vector< RTFCellInfoPtr > RTFColumnVector
bool SetUpdateLayout(bool bUpdate)
DECL_LINK(RTFImportHdl, RtfImportInfo &, void)
#define SAL_WARN(area, stream)
void ImportAsRTF(SvStream &rStream, SdrTableObj &rObj)
SdrOutliner & ImpGetDrawOutliner() const
void ProcToken(RtfImportInfo *pInfo)
std::vector< sal_Int32 > maColumnEdges
bool m_bDetectedRangeSegmentation false
void InsertColumnEdge(sal_Int32 nEdge)