1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DomainMapperTableHandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <DomainMapperTableHandler.hxx>
31 #include <DomainMapper_Impl.hxx>
32 #include <StyleSheetTable.hxx>
33 #include <com/sun/star/table/TableBorderDistances.hpp>
34 #include <com/sun/star/table/TableBorder.hpp>
35 #include <com/sun/star/text/HoriOrientation.hpp>
36 #if OSL_DEBUG_LEVEL > 1
40 namespace writerfilter
{
43 using namespace ::com::sun::star
;
44 using namespace ::std
;
46 #define DEF_BORDER_DIST 190 //0,19cm
47 #define DEFAULT_CELL_MARGIN 108 //default cell margin, not documented
50 static void lcl_printHandle(const Handle_t rHandle
)
54 rtl::OUString aOUStr
= rHandle
->getString();
55 rtl::OString
aOStr(aOUStr
.getStr(), aOUStr
.getLength(), RTL_TEXTENCODING_ASCII_US
);
57 clog
<< aOStr
.getStr() << endl
;
59 static void lcl_printProperties( PropertyMapPtr pProps
)
63 clog
<< "<properties>";
64 PropertyMap::const_iterator aMapIter
= pProps
->begin();
65 PropertyMap::const_iterator aEndIter
= pProps
->end();
66 PropertyNameSupplier
& rPropSupplier
= PropertyNameSupplier::GetPropertyNameSupplier();
67 for( ; aMapIter
!= aEndIter
; ++aMapIter
)
69 rtl::OUString aOUStr
= rPropSupplier
.GetName( aMapIter
->first
.eId
);
70 rtl::OString
aOStr(aOUStr
.getStr(), aOUStr
.getLength(), RTL_TEXTENCODING_ASCII_US
);
71 clog
<< aOStr
.getStr();
73 table::BorderLine aLine
;
75 if ( aMapIter
->second
>>= aLine
)
77 clog
<< ": BorderLine ( Color: " << aLine
.Color
;
78 clog
<< ", Inner: " << aLine
.InnerLineWidth
;
79 clog
<< ", Outer: " << aLine
.OuterLineWidth
<< ") ";
81 else if ( aMapIter
->second
>>= nColor
)
83 clog
<< ": Color ( " << nColor
<< " ) ";
93 DomainMapperTableHandler::DomainMapperTableHandler(TextReference_t xText
, DomainMapper_Impl
& rDMapper_Impl
)
95 m_rDMapper_Impl( rDMapper_Impl
),
101 DomainMapperTableHandler::~DomainMapperTableHandler()
105 void DomainMapperTableHandler::startTable(unsigned int nRows
,
106 unsigned int /*nDepth*/,
107 TablePropertyMapPtr pProps
)
109 m_aTableProperties
= pProps
;
110 m_pTableSeq
= TableSequencePointer_t(new TableSequence_t(nRows
));
113 #if OSL_DEBUG_LEVEL > 1
115 snprintf(sBuffer
, sizeof(sBuffer
), "%d", nRows
);
116 clog
<< "<table rows=\"" << sBuffer
<< "\">" << endl
;
117 lcl_printProperties( pProps
);
121 /*-- 22.02.2008 10:18:37---------------------------------------------------
123 -----------------------------------------------------------------------*/
124 PropertyMapPtr
lcl_SearchParentStyleSheetAndMergeProperties(const StyleSheetEntryPtr pStyleSheet
, StyleSheetTablePtr pStyleSheetTable
)
127 if( pStyleSheet
->sBaseStyleIdentifier
.getLength())
129 const StyleSheetEntryPtr pParentStyleSheet
= pStyleSheetTable
->FindStyleSheetByISTD( pStyleSheet
->sBaseStyleIdentifier
);
130 pRet
= lcl_SearchParentStyleSheetAndMergeProperties( pParentStyleSheet
, pStyleSheetTable
);
134 pRet
.reset( new PropertyMap
);
137 pRet
->insert( pStyleSheet
->pProperties
, true );
141 void lcl_mergeBorder( PropertyIds nId
, PropertyMapPtr pOrig
, PropertyMapPtr pDest
)
143 PropertyDefinition
aDef( nId
, false );
144 PropertyMap::iterator pOrigIt
= pOrig
->find( aDef
);
146 if ( pOrigIt
!= pOrig
->end( ) )
148 pDest
->Insert( nId
, false, pOrigIt
->second
, false );
152 void lcl_computeCellBorders( PropertyMapPtr pTableBorders
, PropertyMapPtr pCellProps
,
153 sal_Int32 nCell
, sal_Int32 nRow
, bool bIsEndCol
, bool bIsEndRow
)
155 PropertyDefinition
aVertPDef( META_PROP_VERTICAL_BORDER
, false );
156 PropertyDefinition
aHorizPDef( META_PROP_HORIZONTAL_BORDER
, false );
158 PropertyMap::iterator aVerticalIter
= pCellProps
->find( aVertPDef
);
159 PropertyMap::iterator aHorizontalIter
= pCellProps
->find( aHorizPDef
);
161 // Handle the vertical and horizontal borders
162 bool bHasVert
= ( aVerticalIter
!= pCellProps
->end( ) );
166 aVerticalIter
= pTableBorders
->find( aVertPDef
);
167 bHasVert
= ( aVerticalIter
!= pTableBorders
->end( ) );
169 aVertProp
= aVerticalIter
->second
;
173 aVertProp
= aVerticalIter
->second
;
174 pCellProps
->erase( aVerticalIter
);
177 bool bHasHoriz
= ( aHorizontalIter
!= pCellProps
->end( ) );
181 aHorizontalIter
= pTableBorders
->find( aHorizPDef
);
182 bHasHoriz
= ( aHorizontalIter
!= pTableBorders
->end( ) );
184 aHorizProp
= aHorizontalIter
->second
;
188 aHorizProp
= aHorizontalIter
->second
;
189 pCellProps
->erase( aHorizontalIter
);
194 lcl_mergeBorder( PROP_LEFT_BORDER
, pTableBorders
, pCellProps
);
196 pCellProps
->Insert( PROP_RIGHT_BORDER
, false, aVertProp
, false );
201 lcl_mergeBorder( PROP_RIGHT_BORDER
, pTableBorders
, pCellProps
);
203 pCellProps
->Insert( PROP_LEFT_BORDER
, false, aVertProp
, false );
206 if ( nCell
> 0 && !bIsEndCol
)
210 pCellProps
->Insert( PROP_RIGHT_BORDER
, false, aVertProp
, false );
211 pCellProps
->Insert( PROP_LEFT_BORDER
, false, aVertProp
, false );
217 lcl_mergeBorder( PROP_TOP_BORDER
, pTableBorders
, pCellProps
);
219 pCellProps
->Insert( PROP_BOTTOM_BORDER
, false, aHorizProp
, false );
224 lcl_mergeBorder( PROP_BOTTOM_BORDER
, pTableBorders
, pCellProps
);
226 pCellProps
->Insert( PROP_TOP_BORDER
, false, aHorizProp
, false );
229 if ( nRow
> 0 && !bIsEndRow
)
233 pCellProps
->Insert( PROP_TOP_BORDER
, false, aHorizProp
, false );
234 pCellProps
->Insert( PROP_BOTTOM_BORDER
, false, aHorizProp
, false );
239 void DomainMapperTableHandler::endTable()
241 #if OSL_DEBUG_LEVEL > 1
243 clog
<< "</table>" << endl
;
244 sal_uInt32 nCells
= 0;
245 sal_uInt32 nRows
= m_aRowProperties
.size();
246 if( nRows
== m_aCellProperties
.size() )
248 for( sal_uInt32 nRow
= 0; nRow
< nRows
; ++nRow
)
249 nCells
+= m_aCellProperties
[nRow
].size();
251 sal_uInt32 nTblPropSize
= m_aTableProperties
.get() ? m_aTableProperties
->size() : 0;
254 ::rtl::OUString sNames
;
257 const beans::PropertyValues aDebugTbl
= m_aTableProperties
->GetPropertyValues();
258 for( sal_uInt32 nDebug
= 0; nDebug
< nTblPropSize
; ++nDebug
)
260 const ::rtl::OUString sName
= aDebugTbl
[nDebug
].Name
;
262 sNames
+= ::rtl::OUString('-');
264 m_aTableProperties
->Invalidate();
265 sNames
+= ::rtl::OUString(' ');
266 clog
<< "Props: " << rtl::OUStringToOString( sNames
, RTL_TEXTENCODING_UTF8
).getStr( ) << endl
;
271 TablePropertyValues_t aTableProperties
;
272 sal_Int32 nLeftBorderDistance
, nRightBorderDistance
, nTopBorderDistance
, nBottomBorderDistance
;
273 nLeftBorderDistance
= nRightBorderDistance
= DEF_BORDER_DIST
;
274 nTopBorderDistance
= nBottomBorderDistance
= 0;
276 PropertyMapPtr
pTableDefaults( new PropertyMap
);
277 PropertyMapPtr
pTableBorders( new PropertyMap
);
279 // will receive the table style if any
280 TableStyleSheetEntry
* pTableStyle
= NULL
;
282 if( m_aTableProperties
.get() )
284 //create properties from the table attributes
285 //...pPropMap->Insert( PROP_LEFT_MARGIN, false, uno::makeAny( m_nLeftMargin - m_nGapHalf ));
286 //pPropMap->Insert( PROP_HORI_ORIENT, false, uno::makeAny( text::HoriOrientation::RIGHT ));
287 sal_Int32 nGapHalf
= 0;
288 sal_Int32 nLeftMargin
= 0;
289 sal_Int32 nTableWidth
= 0;
291 PropertyMap::iterator aTableStyleIter
=
292 m_aTableProperties
->find( PropertyDefinition( META_PROP_TABLE_STYLE_NAME
, false ) );
293 if(aTableStyleIter
!= m_aTableProperties
->end())
295 // Apply table style properties recursively
296 ::rtl::OUString sTableStyleName
;
297 aTableStyleIter
->second
>>= sTableStyleName
;
298 StyleSheetTablePtr pStyleSheetTable
= m_rDMapper_Impl
.GetStyleSheetTable();
299 const StyleSheetEntryPtr pStyleSheet
= pStyleSheetTable
->FindStyleSheetByISTD( sTableStyleName
);
300 pTableStyle
= static_cast<TableStyleSheetEntry
*>( pStyleSheet
.get( ) );
301 m_aTableProperties
->erase( aTableStyleIter
);
305 // First get the style properties, then the table ones
306 PropertyMapPtr
pTableProps( m_aTableProperties
);
307 TablePropertyMapPtr
pEmptyProps( new TablePropertyMap
);
309 m_aTableProperties
= pEmptyProps
;
311 PropertyMapPtr pMergedProperties
= lcl_SearchParentStyleSheetAndMergeProperties(pStyleSheet
, pStyleSheetTable
);
313 m_aTableProperties
->insert( pMergedProperties
);
314 m_aTableProperties
->insert( pTableProps
);
318 // Set the table default attributes for the cells
319 pTableDefaults
->insert( m_aTableProperties
);
321 m_aTableProperties
->getValue( TablePropertyMap::GAP_HALF
, nGapHalf
);
322 m_aTableProperties
->getValue( TablePropertyMap::LEFT_MARGIN
, nLeftMargin
);
324 m_aTableProperties
->getValue( TablePropertyMap::CELL_MAR_LEFT
, nLeftBorderDistance
);
325 m_aTableProperties
->getValue( TablePropertyMap::CELL_MAR_RIGHT
, nRightBorderDistance
);
326 m_aTableProperties
->getValue( TablePropertyMap::CELL_MAR_TOP
, nTopBorderDistance
);
327 m_aTableProperties
->getValue( TablePropertyMap::CELL_MAR_BOTTOM
, nBottomBorderDistance
);
329 table::TableBorderDistances aDistances
;
330 aDistances
.IsTopDistanceValid
=
331 aDistances
.IsBottomDistanceValid
=
332 aDistances
.IsLeftDistanceValid
=
333 aDistances
.IsRightDistanceValid
= sal_True
;
334 aDistances
.TopDistance
= static_cast<sal_Int16
>( nTopBorderDistance
);
335 aDistances
.BottomDistance
= static_cast<sal_Int16
>( nBottomBorderDistance
);
336 aDistances
.LeftDistance
= static_cast<sal_Int16
>( nLeftBorderDistance
);
337 aDistances
.RightDistance
= static_cast<sal_Int16
>( nRightBorderDistance
);
339 m_aTableProperties
->Insert( PROP_TABLE_BORDER_DISTANCES
, false, uno::makeAny( aDistances
) );
341 //table border settings
342 table::TableBorder aTableBorder
;
344 PropertyMap::iterator aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(PROP_TOP_BORDER
, false) );
345 if( aTblBorderIter
!= m_aTableProperties
->end() )
347 aTblBorderIter
->second
>>= aTableBorder
.TopLine
;
348 aTableBorder
.IsTopLineValid
= true;
349 m_aTableProperties
->erase( aTblBorderIter
);
351 pTableBorders
->Insert( PROP_TOP_BORDER
, false, uno::makeAny( aTableBorder
.TopLine
) );
352 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( PROP_TOP_BORDER
, false ) );
353 if ( pIt
!= pTableDefaults
->end( ) )
354 pTableDefaults
->erase( pIt
);
356 aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(PROP_BOTTOM_BORDER
, false) );
357 if( aTblBorderIter
!= m_aTableProperties
->end() )
359 aTblBorderIter
->second
>>= aTableBorder
.BottomLine
;
360 aTableBorder
.IsBottomLineValid
= true;
361 m_aTableProperties
->erase( aTblBorderIter
);
363 pTableBorders
->Insert( PROP_BOTTOM_BORDER
, false, uno::makeAny( aTableBorder
.BottomLine
) );
364 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( PROP_BOTTOM_BORDER
, false ) );
365 if ( pIt
!= pTableDefaults
->end( ) )
366 pTableDefaults
->erase( pIt
);
368 aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(PROP_LEFT_BORDER
, false) );
369 if( aTblBorderIter
!= m_aTableProperties
->end() )
371 aTblBorderIter
->second
>>= aTableBorder
.LeftLine
;
372 aTableBorder
.IsLeftLineValid
= true;
373 m_aTableProperties
->erase( aTblBorderIter
);
375 pTableBorders
->Insert( PROP_LEFT_BORDER
, false, uno::makeAny( aTableBorder
.LeftLine
) );
376 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( PROP_LEFT_BORDER
, false ) );
377 if ( pIt
!= pTableDefaults
->end( ) )
378 pTableDefaults
->erase( pIt
);
380 aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(PROP_RIGHT_BORDER
, false) );
381 if( aTblBorderIter
!= m_aTableProperties
->end() )
383 aTblBorderIter
->second
>>= aTableBorder
.RightLine
;
384 aTableBorder
.IsRightLineValid
= true;
385 m_aTableProperties
->erase( aTblBorderIter
);
387 pTableBorders
->Insert( PROP_RIGHT_BORDER
, false, uno::makeAny( aTableBorder
.RightLine
) );
388 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( PROP_RIGHT_BORDER
, false ) );
389 if ( pIt
!= pTableDefaults
->end( ) )
390 pTableDefaults
->erase( pIt
);
392 aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(META_PROP_HORIZONTAL_BORDER
, false) );
393 if( aTblBorderIter
!= m_aTableProperties
->end() )
395 aTblBorderIter
->second
>>= aTableBorder
.HorizontalLine
;
396 aTableBorder
.IsHorizontalLineValid
= true;
397 m_aTableProperties
->erase( aTblBorderIter
);
399 pTableBorders
->Insert( META_PROP_HORIZONTAL_BORDER
, false, uno::makeAny( aTableBorder
.HorizontalLine
) );
400 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( META_PROP_HORIZONTAL_BORDER
, false ) );
401 if ( pIt
!= pTableDefaults
->end( ) )
402 pTableDefaults
->erase( pIt
);
404 aTblBorderIter
= m_aTableProperties
->find( PropertyDefinition(META_PROP_VERTICAL_BORDER
, false) );
405 if( aTblBorderIter
!= m_aTableProperties
->end() )
407 aTblBorderIter
->second
>>= aTableBorder
.VerticalLine
;
408 aTableBorder
.IsVerticalLineValid
= true;
409 m_aTableProperties
->erase( aTblBorderIter
);
411 pTableBorders
->Insert( META_PROP_VERTICAL_BORDER
, false, uno::makeAny( aTableBorder
.VerticalLine
) );
412 PropertyMap::iterator pIt
= pTableDefaults
->find( PropertyDefinition( META_PROP_VERTICAL_BORDER
, false ) );
413 if ( pIt
!= pTableDefaults
->end( ) )
414 pTableDefaults
->erase( pIt
);
416 aTableBorder
.Distance
= 0;
417 aTableBorder
.IsDistanceValid
= false;
419 m_aTableProperties
->Insert( PROP_TABLE_BORDER
, false, uno::makeAny( aTableBorder
) );
421 m_aTableProperties
->Insert( PROP_LEFT_MARGIN
, false, uno::makeAny( nLeftMargin
- nGapHalf
- nLeftBorderDistance
));
423 m_aTableProperties
->getValue( TablePropertyMap::TABLE_WIDTH
, nTableWidth
);
424 if( nTableWidth
> 0 )
425 m_aTableProperties
->Insert( PROP_WIDTH
, false, uno::makeAny( nTableWidth
));
427 sal_Int32 nHoriOrient
= text::HoriOrientation::LEFT_AND_WIDTH
;
428 m_aTableProperties
->getValue( TablePropertyMap::HORI_ORIENT
, nHoriOrient
) ;
429 m_aTableProperties
->Insert( PROP_HORI_ORIENT
, false, uno::makeAny( sal_Int16(nHoriOrient
) ) );
431 //fill default value - if not available
432 const PropertyMap::const_iterator aRepeatIter
=
433 m_aTableProperties
->find( PropertyDefinition( PROP_HEADER_ROW_COUNT
, false ) );
434 if( aRepeatIter
== m_aTableProperties
->end() )
435 m_aTableProperties
->Insert( PROP_HEADER_ROW_COUNT
, false, uno::makeAny( (sal_Int32
)0 ));
437 // Remove the PROP_HEADER_ROW_COUNT from the table default to avoid
438 // propagating it to the cells
439 PropertyMap::iterator aDefaultRepeatIt
=
440 pTableDefaults
->find( PropertyDefinition( PROP_HEADER_ROW_COUNT
, false ) );
441 if ( aDefaultRepeatIt
!= pTableDefaults
->end( ) )
442 pTableDefaults
->erase( aDefaultRepeatIt
);
444 aTableProperties
= m_aTableProperties
->GetPropertyValues();
447 // expands to uno::Sequence< Sequence< beans::PropertyValues > >
448 CellPropertyValuesSeq_t
aCellProperties( m_aCellProperties
.size() );
450 // std::vector< std::vector<PropertyMapPtr> > m_aCellProperties
451 PropertyMapVector2::const_iterator aRowOfCellsIterator
= m_aCellProperties
.begin();
452 PropertyMapVector2::const_iterator aRowOfCellsIteratorEnd
= m_aCellProperties
.end();
453 PropertyMapVector2::const_iterator aLastRowIterator
= m_aCellProperties
.end() - 1;
456 //it's a uno::Sequence< beans::PropertyValues >*
457 RowPropertyValuesSeq_t
* pCellProperties
= aCellProperties
.getArray();
458 while( aRowOfCellsIterator
!= aRowOfCellsIteratorEnd
)
460 //aRowOfCellsIterator points to a vector of PropertyMapPtr
461 PropertyMapVector1::const_iterator aCellIterator
= aRowOfCellsIterator
->begin();
462 PropertyMapVector1::const_iterator aCellIteratorEnd
= aRowOfCellsIterator
->end();
463 PropertyMapVector1::const_iterator aLastCellIterator
= aRowOfCellsIterator
->end() - 1;
465 // Get the row style properties
466 sal_Int32 nRowStyleMask
= sal_Int32( 0 );
467 PropertyMapPtr pRowProps
= m_aRowProperties
[nRow
];
468 if ( pRowProps
.get( ) )
470 PropertyMap::iterator pTcCnfStyleIt
= pRowProps
->find( PropertyDefinition( PROP_CNF_STYLE
, true ) );
471 if ( pTcCnfStyleIt
!= pRowProps
->end( ) )
476 pTcCnfStyleIt
->second
>>= sMask
;
477 nRowStyleMask
= sMask
.toInt32( 2 );
479 pRowProps
->erase( pTcCnfStyleIt
);
484 pCellProperties
[nRow
].realloc( aRowOfCellsIterator
->size() );
485 beans::PropertyValues
* pSingleCellProperties
= pCellProperties
[nRow
].getArray();
486 while( aCellIterator
!= aCellIteratorEnd
)
488 PropertyMapPtr
pAllCellProps( new PropertyMap
);
490 bool bIsEndCol
= aCellIterator
== aLastCellIterator
;
491 bool bIsEndRow
= aRowOfCellsIterator
== aLastRowIterator
;
493 //aCellIterator points to a PropertyMapPtr;
494 if( aCellIterator
->get() )
496 if ( pTableDefaults
->size( ) )
497 pAllCellProps
->insert( pTableDefaults
);
499 // Fill the cell properties with the ones of the style
500 sal_Int32 nCellStyleMask
= 0;
501 const PropertyMap::iterator aCnfStyleIter
=
502 aCellIterator
->get()->find( PropertyDefinition( PROP_CNF_STYLE
, false ) );
503 if ( aCnfStyleIter
!= aCellIterator
->get( )->end( ) )
507 aCnfStyleIter
->second
>>= sMask
;
508 nCellStyleMask
= sMask
.toInt32( 2 );
510 aCellIterator
->get( )->erase( aCnfStyleIter
);
515 PropertyMapPtr pStyleProps
= pTableStyle
->GetProperties( nCellStyleMask
+ nRowStyleMask
);
516 pAllCellProps
->insert( pStyleProps
);
519 // Then add the cell properties
520 pAllCellProps
->insert( *aCellIterator
);
521 aCellIterator
->get( )->swap( *pAllCellProps
.get( ) );
524 clog
<< "Cell #" << nCell
<< ", Row #" << nRow
<< endl
;
527 lcl_computeCellBorders( pTableBorders
, *aCellIterator
, nCell
, nRow
, bIsEndCol
, bIsEndRow
);
529 //now set the default left+right border distance TODO: there's an sprm containing the default distance!
530 const PropertyMap::const_iterator aLeftDistanceIter
=
531 aCellIterator
->get()->find( PropertyDefinition(PROP_LEFT_BORDER_DISTANCE
, false) );
532 if( aLeftDistanceIter
== aCellIterator
->get()->end() )
533 aCellIterator
->get()->Insert( PROP_LEFT_BORDER_DISTANCE
, false,
534 uno::makeAny(nLeftBorderDistance
) );
535 const PropertyMap::const_iterator aRightDistanceIter
=
536 aCellIterator
->get()->find( PropertyDefinition(PROP_RIGHT_BORDER_DISTANCE
, false) );
537 if( aRightDistanceIter
== aCellIterator
->get()->end() )
538 aCellIterator
->get()->Insert( PROP_RIGHT_BORDER_DISTANCE
, false,
539 uno::makeAny((sal_Int32
) nRightBorderDistance
) );
541 const PropertyMap::const_iterator aTopDistanceIter
=
542 aCellIterator
->get()->find( PropertyDefinition(PROP_TOP_BORDER_DISTANCE
, false) );
543 if( aTopDistanceIter
== aCellIterator
->get()->end() )
544 aCellIterator
->get()->Insert( PROP_TOP_BORDER_DISTANCE
, false,
545 uno::makeAny((sal_Int32
) nTopBorderDistance
) );
547 const PropertyMap::const_iterator aBottomDistanceIter
=
548 aCellIterator
->get()->find( PropertyDefinition(PROP_BOTTOM_BORDER_DISTANCE
, false) );
549 if( aBottomDistanceIter
== aCellIterator
->get()->end() )
550 aCellIterator
->get()->Insert( PROP_BOTTOM_BORDER_DISTANCE
, false,
551 uno::makeAny((sal_Int32
) nBottomBorderDistance
) );
553 pSingleCellProperties
[nCell
] = aCellIterator
->get()->GetPropertyValues();
558 #if OSL_DEBUG_LEVEL > 1
559 //-->debug cell properties
561 ::rtl::OUString sNames
;
562 const uno::Sequence
< beans::PropertyValues
> aDebugCurrentRow
= aCellProperties
[nRow
];
563 sal_Int32 nDebugCells
= aDebugCurrentRow
.getLength();
565 for( sal_Int32 nDebugCell
= 0; nDebugCell
< nDebugCells
; ++nDebugCell
)
567 const uno::Sequence
< beans::PropertyValue
>& aDebugCellProperties
= aDebugCurrentRow
[nDebugCell
];
568 sal_Int32 nDebugCellProperties
= aDebugCellProperties
.getLength();
569 for( sal_Int32 nDebugProperty
= 0; nDebugProperty
< nDebugCellProperties
; ++nDebugProperty
)
571 const ::rtl::OUString sName
= aDebugCellProperties
[nDebugProperty
].Name
;
573 sNames
+= ::rtl::OUString('-');
575 sNames
+= ::rtl::OUString('\n');
582 ++aRowOfCellsIterator
;
584 #if OSL_DEBUG_LEVEL > 1
585 //-->debug cell properties of all rows
587 ::rtl::OUString sNames
;
588 for( sal_Int32 nDebugRow
= 0; nDebugRow
< aCellProperties
.getLength(); ++nDebugRow
)
590 const uno::Sequence
< beans::PropertyValues
> aDebugCurrentRow
= aCellProperties
[nDebugRow
];
591 sal_Int32 nDebugCells
= aDebugCurrentRow
.getLength();
593 for( sal_Int32 nDebugCell
= 0; nDebugCell
< nDebugCells
; ++nDebugCell
)
595 const uno::Sequence
< beans::PropertyValue
>& aDebugCellProperties
= aDebugCurrentRow
[nDebugCell
];
596 sal_Int32 nDebugCellProperties
= aDebugCellProperties
.getLength();
597 for( sal_Int32 nDebugProperty
= 0; nDebugProperty
< nDebugCellProperties
; ++nDebugProperty
)
599 const ::rtl::OUString sName
= aDebugCellProperties
[nDebugProperty
].Name
;
601 sNames
+= ::rtl::OUString('-');
603 sNames
+= ::rtl::OUString('+');
605 sNames
+= ::rtl::OUString('|');
612 RowPropertyValuesSeq_t
aRowProperties( m_aRowProperties
.size() );
613 PropertyMapVector1::const_iterator aRowIter
= m_aRowProperties
.begin();
614 PropertyMapVector1::const_iterator aRowIterEnd
= m_aRowProperties
.end();
616 while( aRowIter
!= aRowIterEnd
)
618 if( aRowIter
->get() )
620 //set default to 'break across pages"
621 if( aRowIter
->get()->find( PropertyDefinition( PROP_IS_SPLIT_ALLOWED
, false )) == aRowIter
->get()->end())
622 aRowIter
->get()->Insert( PROP_IS_SPLIT_ALLOWED
, false, uno::makeAny(sal_True
) );
624 aRowProperties
[nRow
] = aRowIter
->get()->GetPropertyValues();
630 if (m_pTableSeq
->getLength() > 0)
634 #if OSL_DEBUG_LEVEL > 1
636 sal_Int32 nCellPropertiesRows
= aCellProperties
.getLength();
637 sal_Int32 nCellPropertiesCells
= aCellProperties
[0].getLength();
638 sal_Int32 nCellPropertiesProperties
= aCellProperties
[0][0].getLength();
639 (void) nCellPropertiesRows
;
640 (void) nCellPropertiesCells
;
641 (void) nCellPropertiesProperties
;
642 ++nCellPropertiesProperties
;
644 clog
<< "Converting table" << endl
;
647 uno::Reference
<text::XTextTable
> xTable
= m_xText
->convertToTable(*m_pTableSeq
,
652 m_xTableRange
= xTable
->getAnchor( );
654 catch (lang::IllegalArgumentException e
)
656 #if OSL_DEBUG_LEVEL > 1
657 clog
<< "failed to import table!" << endl
;
660 #if OSL_DEBUG_LEVEL > 1
661 catch ( uno::Exception e
)
663 clog
<< "Caught an other exception: " << rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_UTF8
).getStr( ) << endl
;
668 m_aTableProperties
.reset();
669 m_aCellProperties
.clear();
670 m_aRowProperties
.clear();
673 void DomainMapperTableHandler::startRow(unsigned int nCells
,
674 TablePropertyMapPtr pProps
)
676 m_aRowProperties
.push_back( pProps
);
677 m_aCellProperties
.push_back( PropertyMapVector1() );
679 #if OSL_DEBUG_LEVEL > 1
681 snprintf(sBuffer
, sizeof(sBuffer
), "%d", nCells
);
683 clog
<< "<table.row cells=\"" << sBuffer
<< "\">" << endl
;
684 lcl_printProperties( pProps
);
687 m_pRowSeq
= RowSequencePointer_t(new RowSequence_t(nCells
));
691 void DomainMapperTableHandler::endRow()
693 (*m_pTableSeq
)[m_nRowIndex
] = *m_pRowSeq
;
696 #if OSL_DEBUG_LEVEL > 1
697 clog
<< "</table.row>" << endl
;
701 void DomainMapperTableHandler::startCell(const Handle_t
& start
,
702 TablePropertyMapPtr pProps
)
704 sal_uInt32 nRow
= m_aRowProperties
.size();
706 m_aCellProperties
[nRow
- 1].push_back( pProps
);
709 // Adding an empty cell properties map to be able to get
710 // the table defaults properties
711 TablePropertyMapPtr
pEmptyProps( new TablePropertyMap( ) );
712 m_aCellProperties
[nRow
- 1].push_back( pEmptyProps
);
715 #if OSL_DEBUG_LEVEL > 1
716 clog
<< "<table.cell>";
717 lcl_printHandle(start
);
718 lcl_printProperties( pProps
);
722 //add a new 'row' of properties
723 // if( m_pCellProperties.size() <= sal::static_int_cast< sal_uInt32, sal_Int32>(m_nRowIndex) )
724 // m_pCellProperties.push_back( RowProperties_t() );
725 // m_pCellProperties[m_nRowIndex].push_back( pProps );
726 m_pCellSeq
= CellSequencePointer_t(new CellSequence_t(2));
729 (*m_pCellSeq
)[0] = start
->getStart();
732 void DomainMapperTableHandler::endCell(const Handle_t
& end
)
734 #if OSL_DEBUG_LEVEL > 1
735 lcl_printHandle(end
);
736 clog
<< "</table.cell>" << endl
;
741 (*m_pCellSeq
)[1] = end
->getEnd();
742 (*m_pRowSeq
)[m_nCellIndex
] = *m_pCellSeq
;