24 #include <com/sun/star/table/XTable.hpp>
25 #include <com/sun/star/table/XMergeableCellRange.hpp>
36 #include <editeng/editeng.hxx>
60 explicit RTFCellDefault(
SfxItemPool* pPool ) : maItemSet( *pPool ), mnRowSpan(1), mnColSpan(1), mnCellX(0) {}
78 explicit RTFCellInfo(
SfxItemPool& rPool ) : maItemSet( rPool ), mnStartPara(0), mnParaCount(0), mnCellX(0), mnRowSpan(1) {}
127 std::vector< RTFColumnVectorPtr >
maRows;
142 : mrTableObj( rTableObj )
144 , mrItemPool( rTableObj.getSdrModelFromSdrObject().GetItemPool() )
151 , mpActDefault( nullptr )
152 , mpDefMerge( nullptr )
153 , mxTable( rTableObj.getTable() )
166 mpOutliner->Read( rStream, OUString(), EETextFormat::Rtf );
174 switch ( rInfo.eState )
176 case RtfImportState::NextToken:
179 case RtfImportState::UnknownAttr:
182 case RtfImportState::Start:
190 case RtfImportState::End:
191 if ( rInfo.aSelection.nEndPos )
193 mpActDefault =
nullptr;
195 rInfo.aSelection.nEndPara++;
199 case RtfImportState::SetAttr:
200 case RtfImportState::InsertText:
201 case RtfImportState::InsertPara:
204 SAL_WARN(
"svx.table",
"unknown ImportInfo.eState");
218 RTFCellInfoPtr xCellInfo = std::make_shared<RTFCellInfo>(
mrItemPool);
233 if ( xCellInfo->mnRowSpan == 0 &&
mnVMergeIdx < nSize )
236 if (xLastCell->mnRowSpan)
237 xCellInfo->mxVMergeCell = xLastCell;
239 xCellInfo->mxVMergeCell = xLastCell->mxVMergeCell;
246 if ( xCellInfo->mxVMergeCell )
249 xColumn->back()->mxVMergeCell != xCellInfo->mxVMergeCell )
250 xCellInfo->mxVMergeCell->mnRowSpan++;
253 xColumn->push_back( xCellInfo );
263 if ( aNextEdge ==
maColumnEdges.end() || nEdge != *aNextEdge )
275 Reference< XTableColumns > xCols(
mxTable->getColumns(), UNO_SET_THROW );
277 if( nColCount < nColMax )
279 xCols->insertByIndex( nColCount, nColMax - nColCount );
280 nColCount =
mxTable->getColumnCount();
283 const OUString sWidth(
"Width");
284 sal_Int32 nCol, nLastEdge = 0;
285 for( nCol = 0; nCol <
nColCount; nCol++ )
290 xSet->setPropertyValue( sWidth,
Any( nWidth ) );
294 const sal_Int32 nRowCount =
mxTable->getRowCount();
297 Reference< XTableRows > xRows(
mxTable->getRows(), UNO_SET_THROW );
298 xRows->insertByIndex( nRowCount,
mnRowCnt - nRowCount );
301 for( sal_Int32 nRow = 0; nRow < static_cast<sal_Int32>(
maRows.size()); nRow++ )
306 for( sal_Int32 nIdx = 0; nCol < nColMax && nIdx < static_cast<sal_Int32>(xColumn->size()); nIdx++ )
308 RTFCellInfoPtr xCellInfo( (*xColumn)[nIdx] );
310 CellRef xCell( dynamic_cast< Cell* >(
mxTable->getCellByPosition( nCol, nRow ).get() ) );
311 if( xCell.is() && xCellInfo )
314 if( xCellInfo->maItemSet.GetItemState(
SDRATTR_TABLE_BORDER,
false,&pPoolItem)==SfxItemState::SET)
315 xCell->SetMergedItem( *pPoolItem );
317 std::unique_ptr<OutlinerParaObject> pTextObject(
mpOutliner->CreateParaObject( xCellInfo->mnStartPara, xCellInfo->mnParaCount ));
322 rOutliner.
SetText( *pTextObject );
326 sal_Int32 nLastRow = nRow;
327 if ( xCellInfo->mnRowSpan )
328 nLastRow += xCellInfo->mnRowSpan - 1;
330 aEdge = std::lower_bound( aEdge,
maColumnEdges.end(), xCellInfo->mnCellX );
331 sal_Int32 nLastCol = nCol;
338 if ( nLastCol > nCol || nLastRow > nRow )
340 Reference< XMergeableCellRange > xRange(
mxTable->createCursorByRange(
mxTable->getCellRangeByPosition( nCol, nRow, nLastCol, nLastRow ) ), UNO_QUERY_THROW );
341 if( xRange->isMergeable() )
350 aRect.
SetRight( aRect.Left() + nLastEdge );
366 maRows.push_back( std::make_shared<std::vector<std::shared_ptr<RTFCellInfo>>>( ) );
434 std::shared_ptr<RTFCellDefault> pDefault(
mpInsDefault.release() );
442 pDefault->mnCellX = nSize;
503 aParser.
Read( rStream );
#define LINK(Instance, Class, Member)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
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)
RTFPardAttrMapIds & GetPardMap()
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)
SdrTableRTFParser & operator=(const SdrTableRTFParser &)=delete
#define TOOLS_WARN_EXCEPTION(area, stream)
void SetText(const OutlinerParaObject &)
#define DBG_ASSERT(sCon, aError)
static tools::Long TwipsToHundMM(tools::Long nIn)
std::vector< std::shared_ptr< RTFCellDefault > > RTFCellDefaultVector
const Link< RtfImportInfo &, void > & GetRtfImportHdl() const
SvParser< int > * pParser
RTFCellDefaultVector::iterator maDefaultIterator
std::vector< RTFColumnVectorPtr > maRows
constexpr TypedWhichId< SvxBoxItem > SDRATTR_TABLE_BORDER(SDRATTR_TABLE_FIRST+0)
std::unique_ptr< OutlinerParaObject > CreateParaObject(sal_Int32 nStartPara=0, sal_Int32 nParaCount=EE_PARA_ALL) const
RTFCellDefault * mpActDefault
std::unique_ptr< RTFCellDefault > mpInsDefault
SdrTableRTFParser(SdrTableObj &rTableObj)
void NbcSetOutlinerParaObjectForText(std::unique_ptr< OutlinerParaObject > pTextObject, SdrText *pText)
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
void SetUpdateMode(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
void InsertColumnEdge(sal_Int32 nEdge)