Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/text/XTextTable.hpp>
21 : #include <com/sun/star/text/XTextSection.hpp>
22 :
23 : #include <hintids.hxx>
24 : #include <rtl/ustrbuf.hxx>
25 : #include <xmloff/xmlnmspe.hxx>
26 : #include <xmloff/xmltoken.hxx>
27 : #include <xmloff/xmluconv.hxx>
28 : #include <xmloff/numehelp.hxx>
29 : #include <svl/zforlist.hxx>
30 : #include <editeng/brushitem.hxx>
31 : #include <editeng/boxitem.hxx>
32 : #include <fmtrowsplt.hxx>
33 : #include <editeng/frmdiritem.hxx>
34 : #include <list>
35 : #include "swtable.hxx"
36 : #include "doc.hxx"
37 : #include "pam.hxx"
38 : #include "frmfmt.hxx"
39 : #include "wrtswtbl.hxx"
40 : #include "fmtfsize.hxx"
41 : #include "fmtornt.hxx"
42 : #include "cellatr.hxx"
43 : #include "ddefld.hxx"
44 : #include "swddetbl.hxx"
45 : #include <ndole.hxx>
46 : #include <xmloff/nmspmap.hxx>
47 : #include <sfx2/linkmgr.hxx>
48 : #include "unotbl.hxx"
49 : #include "xmltexte.hxx"
50 : #include "xmlexp.hxx"
51 : #include <o3tl/sorted_vector.hxx>
52 : #include <textboxhelper.hxx>
53 :
54 : using namespace ::com::sun::star;
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::text;
57 : using namespace ::com::sun::star::beans;
58 : using namespace ::com::sun::star::lang;
59 : using namespace ::com::sun::star::container;
60 : using namespace ::xmloff::token;
61 : using table::XCell;
62 : using ::std::vector;
63 : using ::std::advance;
64 :
65 488 : class SwXMLTableColumn_Impl : public SwWriteTableCol
66 : {
67 : OUString sStyleName;
68 : sal_uInt32 nRelWidth;
69 :
70 : public:
71 :
72 488 : explicit SwXMLTableColumn_Impl(sal_uInt32 nPosition)
73 : : SwWriteTableCol(nPosition)
74 488 : , nRelWidth(0UL)
75 488 : {};
76 :
77 53 : void SetStyleName( const OUString& rName ) { sStyleName = rName; }
78 176 : const OUString& GetStyleName() const { return sStyleName; }
79 :
80 8 : void SetRelWidth( sal_uInt32 nSet ) { nRelWidth = nSet; }
81 61 : sal_uInt32 GetRelWidth() const { return nRelWidth; }
82 : };
83 :
84 : struct SwXMLTableColumnCmpWidth_Impl
85 : {
86 176 : bool operator()( SwXMLTableColumn_Impl* const& lhs, SwXMLTableColumn_Impl* const& rhs ) const
87 : {
88 176 : sal_Int32 n = (sal_Int32)lhs->GetWidthOpt() - (sal_Int32)rhs->GetWidthOpt();
89 176 : if( !n )
90 0 : n = (sal_Int32)lhs->GetRelWidth() - (sal_Int32)rhs->GetRelWidth();
91 176 : return n < 0;
92 : }
93 : };
94 :
95 14 : class SwXMLTableColumns_Impl : public o3tl::sorted_vector<SwXMLTableColumn_Impl*, o3tl::less_ptr_to<SwXMLTableColumn_Impl> > {
96 : public:
97 14 : ~SwXMLTableColumns_Impl() { DeleteAndDestroyAll(); }
98 : };
99 :
100 28 : class SwXMLTableColumnsSortByWidth_Impl : public o3tl::sorted_vector<SwXMLTableColumn_Impl*, SwXMLTableColumnCmpWidth_Impl> {};
101 :
102 : class SwXMLTableLines_Impl
103 : {
104 : SwXMLTableColumns_Impl aCols;
105 : const SwTableLines *pLines;
106 : sal_uInt32 nWidth;
107 :
108 : public:
109 :
110 : explicit SwXMLTableLines_Impl( const SwTableLines& rLines );
111 :
112 14 : ~SwXMLTableLines_Impl() {}
113 :
114 84 : sal_uInt32 GetWidth() const { return nWidth; }
115 12 : const SwTableLines *GetLines() const { return pLines; }
116 :
117 712 : const SwXMLTableColumns_Impl& GetColumns() const { return aCols; }
118 : };
119 :
120 14 : SwXMLTableLines_Impl::SwXMLTableLines_Impl( const SwTableLines& rLines ) :
121 : pLines( &rLines ),
122 14 : nWidth( 0UL )
123 : {
124 : #if OSL_DEBUG_LEVEL > 0
125 : sal_uInt32 nEndCPos = 0U;
126 : #endif
127 14 : const size_t nLines = rLines.size();
128 58 : for( size_t nLine=0U; nLine<nLines; ++nLine )
129 : {
130 44 : const SwTableLine *pLine = rLines[nLine];
131 44 : const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
132 44 : const size_t nBoxes = rBoxes.size();
133 :
134 44 : sal_uInt32 nCPos = 0U;
135 219 : for( size_t nBox=0U; nBox<nBoxes; ++nBox )
136 : {
137 175 : const SwTableBox *pBox = rBoxes[nBox];
138 :
139 175 : if( nBox < nBoxes-1U || nWidth==0UL )
140 : {
141 145 : nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
142 : SwXMLTableColumn_Impl *pCol =
143 145 : new SwXMLTableColumn_Impl( nCPos );
144 :
145 145 : if( !aCols.insert( pCol ).second )
146 92 : delete pCol;
147 :
148 145 : if( nBox==nBoxes-1U )
149 : {
150 : OSL_ENSURE( nLine==0U && nWidth==0UL,
151 : "parent width will be lost" );
152 14 : nWidth = nCPos;
153 145 : }
154 : }
155 : else
156 : {
157 : #if OSL_DEBUG_LEVEL > 0
158 : sal_uInt32 nCheckPos =
159 : nCPos + SwWriteTable::GetBoxWidth( pBox );
160 : if( !nEndCPos )
161 : {
162 : nEndCPos = nCheckPos;
163 : }
164 : #endif
165 30 : nCPos = nWidth;
166 : #if OSL_DEBUG_LEVEL > 0
167 : SwXMLTableColumn_Impl aCol( nWidth );
168 : OSL_ENSURE( aCols.find(&aCol) != aCols.end(), "couldn't find last column" );
169 : OSL_ENSURE( SwXMLTableColumn_Impl(nCheckPos) ==
170 : SwXMLTableColumn_Impl(nCPos),
171 : "rows have different total widths" );
172 : #endif
173 : }
174 : }
175 : }
176 14 : }
177 :
178 : typedef vector< SwFrameFormat* > SwXMLFrameFormats_Impl;
179 :
180 56 : class SwXMLTableFrameFormatsSort_Impl
181 : {
182 : private:
183 : SwXMLFrameFormats_Impl aFormatList;
184 : public:
185 : bool AddRow( SwFrameFormat& rFrameFormat, const OUString& rNamePrefix, sal_uInt32 nLine );
186 : bool AddCell( SwFrameFormat& rFrameFormat, const OUString& rNamePrefix,
187 : sal_uInt32 nCol, sal_uInt32 nRow, bool bTop );
188 : };
189 :
190 44 : bool SwXMLTableFrameFormatsSort_Impl::AddRow( SwFrameFormat& rFrameFormat,
191 : const OUString& rNamePrefix,
192 : sal_uInt32 nLine )
193 : {
194 44 : const SwFormatFrmSize *pFrmSize = 0;
195 44 : const SwFormatRowSplit* pRowSplit = 0;
196 44 : const SvxBrushItem *pBrush = 0;
197 :
198 44 : const SfxItemSet& rItemSet = rFrameFormat.GetAttrSet();
199 : const SfxPoolItem *pItem;
200 44 : if( SfxItemState::SET == rItemSet.GetItemState( RES_FRM_SIZE, false, &pItem ) )
201 12 : pFrmSize = static_cast<const SwFormatFrmSize *>(pItem);
202 :
203 44 : if( SfxItemState::SET == rItemSet.GetItemState( RES_ROW_SPLIT, false, &pItem ) )
204 36 : pRowSplit = static_cast<const SwFormatRowSplit *>(pItem);
205 :
206 44 : if( SfxItemState::SET == rItemSet.GetItemState( RES_BACKGROUND, false, &pItem ) )
207 0 : pBrush = static_cast<const SvxBrushItem *>(pItem);
208 :
209 : // empty styles have not to be exported
210 44 : if( !pFrmSize && !pBrush && !pRowSplit )
211 8 : return false;
212 :
213 : // order is: -/brush, size/-, size/brush
214 36 : bool bInsert = true;
215 36 : SwXMLFrameFormats_Impl::iterator i;
216 44 : for( i = aFormatList.begin(); i < aFormatList.end(); ++i )
217 : {
218 29 : const SwFormatFrmSize *pTestFrmSize = 0;
219 29 : const SwFormatRowSplit* pTestRowSplit = 0;
220 29 : const SvxBrushItem *pTestBrush = 0;
221 29 : const SwFrameFormat *pTestFormat = *i;
222 29 : const SfxItemSet& rTestSet = pTestFormat->GetAttrSet();
223 29 : if( SfxItemState::SET == rTestSet.GetItemState( RES_FRM_SIZE, false,
224 29 : &pItem ) )
225 : {
226 13 : if( !pFrmSize )
227 5 : break;
228 :
229 8 : pTestFrmSize = static_cast<const SwFormatFrmSize *>(pItem);
230 : }
231 : else
232 : {
233 16 : if( pFrmSize )
234 3 : continue;
235 : }
236 :
237 21 : if( SfxItemState::SET == rTestSet.GetItemState( RES_BACKGROUND, false,
238 21 : &pItem ) )
239 : {
240 0 : if( !pBrush )
241 0 : break;
242 :
243 0 : pTestBrush = static_cast<const SvxBrushItem *>(pItem);
244 : }
245 : else
246 : {
247 21 : if( pBrush )
248 0 : continue;
249 : }
250 :
251 21 : if( SfxItemState::SET == rTestSet.GetItemState( RES_ROW_SPLIT, false,
252 21 : &pItem ) )
253 : {
254 21 : if( !pRowSplit )
255 0 : break;
256 :
257 21 : pTestRowSplit = static_cast<const SwFormatRowSplit *>(pItem);
258 : }
259 : else
260 : {
261 0 : if( pRowSplit )
262 0 : continue;
263 : }
264 :
265 34 : if( pFrmSize &&
266 16 : ( pFrmSize->GetHeightSizeType() != pTestFrmSize->GetHeightSizeType() ||
267 8 : pFrmSize->GetHeight() != pTestFrmSize->GetHeight() ) )
268 5 : continue;
269 :
270 16 : if( pBrush && (*pBrush != *pTestBrush) )
271 0 : continue;
272 :
273 16 : if( pRowSplit && (!pRowSplit->GetValue() != !pTestRowSplit->GetValue()) )
274 0 : continue;
275 :
276 : // found!
277 16 : rFrameFormat.SetName( pTestFormat->GetName() );
278 16 : bInsert = false;
279 16 : break;
280 : }
281 :
282 36 : if( bInsert )
283 : {
284 20 : rFrameFormat.SetName( rNamePrefix + "." + OUString::number(nLine+1UL) );
285 20 : if ( i != aFormatList.end() ) ++i;
286 20 : aFormatList.insert( i, &rFrameFormat );
287 : }
288 :
289 36 : return bInsert;
290 : }
291 :
292 24 : static OUString lcl_xmltble_appendBoxPrefix(const OUString& rNamePrefix,
293 : sal_uInt32 nCol, sal_uInt32 nRow, bool bTop )
294 : {
295 24 : if( bTop )
296 : {
297 24 : OUString sTmp;
298 24 : sw_GetTableBoxColStr( (sal_uInt16)nCol, sTmp );
299 24 : return rNamePrefix + "." + sTmp + OUString::number(nRow + 1);
300 : }
301 : return rNamePrefix
302 0 : + "." + OUString::number(nCol + 1)
303 0 : + "." + OUString::number(nRow + 1);
304 : }
305 :
306 175 : bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
307 : const OUString& rNamePrefix,
308 : sal_uInt32 nCol, sal_uInt32 nRow, bool bTop )
309 : {
310 175 : const SwFormatVertOrient *pVertOrient = 0;
311 175 : const SvxBrushItem *pBrush = 0;
312 175 : const SvxBoxItem *pBox = 0;
313 175 : const SwTableBoxNumFormat *pNumFormat = 0;
314 175 : const SvxFrameDirectionItem *pFrameDir = 0;
315 :
316 175 : const SfxItemSet& rItemSet = rFrameFormat.GetAttrSet();
317 : const SfxPoolItem *pItem;
318 175 : if( SfxItemState::SET == rItemSet.GetItemState( RES_VERT_ORIENT, false,
319 175 : &pItem ) )
320 0 : pVertOrient = static_cast<const SwFormatVertOrient *>(pItem);
321 :
322 175 : if( SfxItemState::SET == rItemSet.GetItemState( RES_BACKGROUND, false, &pItem ) )
323 161 : pBrush = static_cast<const SvxBrushItem *>(pItem);
324 :
325 175 : if( SfxItemState::SET == rItemSet.GetItemState( RES_BOX, false, &pItem ) )
326 175 : pBox = static_cast<const SvxBoxItem *>(pItem);
327 :
328 175 : if ( SfxItemState::SET == rItemSet.GetItemState( RES_BOXATR_FORMAT,
329 175 : false, &pItem ) )
330 0 : pNumFormat = static_cast<const SwTableBoxNumFormat *>(pItem);
331 175 : if ( SfxItemState::SET == rItemSet.GetItemState( RES_FRAMEDIR,
332 175 : false, &pItem ) )
333 0 : pFrameDir = static_cast<const SvxFrameDirectionItem *>(pItem);
334 :
335 : // empty styles have not to be exported
336 175 : if( !pVertOrient && !pBrush && !pBox && !pNumFormat && !pFrameDir )
337 0 : return false;
338 :
339 : // order is: -/-/-/num,
340 : // -/-/box/-, --/-/box/num,
341 : // -/brush/-/-, -/brush/-/num, -/brush/box/-, -/brush/box/num,
342 : // vert/-/-/-, vert/-/-/num, vert/-/box/-, ver/-/box/num,
343 : // vert/brush/-/-, vert/brush/-/num, vert/brush/box/-,
344 : // vert/brush/box/num
345 175 : bool bInsert = true;
346 175 : SwXMLFrameFormats_Impl::iterator i;
347 193 : for( i = aFormatList.begin(); i < aFormatList.end(); ++i )
348 : {
349 169 : const SwFormatVertOrient *pTestVertOrient = 0;
350 169 : const SvxBrushItem *pTestBrush = 0;
351 169 : const SvxBoxItem *pTestBox = 0;
352 169 : const SwTableBoxNumFormat *pTestNumFormat = 0;
353 169 : const SvxFrameDirectionItem *pTestFrameDir = 0;
354 169 : const SwFrameFormat* pTestFormat = *i;
355 169 : const SfxItemSet& rTestSet = pTestFormat->GetAttrSet();
356 169 : if( SfxItemState::SET == rTestSet.GetItemState( RES_VERT_ORIENT, false,
357 169 : &pItem ) )
358 : {
359 0 : if( !pVertOrient )
360 0 : break;
361 :
362 0 : pTestVertOrient = static_cast<const SwFormatVertOrient *>(pItem);
363 : }
364 : else
365 : {
366 169 : if( pVertOrient )
367 0 : continue;
368 : }
369 :
370 169 : if( SfxItemState::SET == rTestSet.GetItemState( RES_BACKGROUND, false,
371 169 : &pItem ) )
372 : {
373 151 : if( !pBrush )
374 0 : break;
375 :
376 151 : pTestBrush = static_cast<const SvxBrushItem *>(pItem);
377 : }
378 : else
379 : {
380 18 : if( pBrush )
381 0 : continue;
382 : }
383 :
384 169 : if( SfxItemState::SET == rTestSet.GetItemState( RES_BOX, false, &pItem ) )
385 : {
386 169 : if( !pBox )
387 0 : break;
388 :
389 169 : pTestBox = static_cast<const SvxBoxItem *>(pItem);
390 : }
391 : else
392 : {
393 0 : if( pBox )
394 0 : continue;
395 : }
396 :
397 169 : if ( SfxItemState::SET == rTestSet.GetItemState( RES_BOXATR_FORMAT,
398 169 : false, &pItem ) )
399 : {
400 0 : if( !pNumFormat )
401 0 : break;
402 :
403 0 : pTestNumFormat = static_cast<const SwTableBoxNumFormat *>(pItem);
404 : }
405 : else
406 : {
407 169 : if( pNumFormat )
408 0 : continue;
409 :
410 : }
411 :
412 169 : if ( SfxItemState::SET == rTestSet.GetItemState( RES_FRAMEDIR,
413 169 : false, &pItem ) )
414 : {
415 0 : if( !pFrameDir )
416 0 : break;
417 :
418 0 : pTestFrameDir = static_cast<const SvxFrameDirectionItem *>(pItem);
419 : }
420 : else
421 : {
422 169 : if( pFrameDir )
423 0 : continue;
424 :
425 : }
426 :
427 169 : if( pVertOrient &&
428 0 : pVertOrient->GetVertOrient() != pTestVertOrient->GetVertOrient() )
429 0 : continue;
430 :
431 169 : if( pBrush && ( *pBrush != *pTestBrush ) )
432 0 : continue;
433 :
434 169 : if( pBox && ( *pBox != *pTestBox ) )
435 18 : continue;
436 :
437 151 : if( pNumFormat && pNumFormat->GetValue() != pTestNumFormat->GetValue() )
438 0 : continue;
439 :
440 151 : if( pFrameDir && pFrameDir->GetValue() != pTestFrameDir->GetValue() )
441 0 : continue;
442 :
443 : // found!
444 151 : rFrameFormat.SetName( pTestFormat->GetName() );
445 151 : bInsert = false;
446 151 : break;
447 : }
448 :
449 175 : if( bInsert )
450 : {
451 24 : rFrameFormat.SetName( lcl_xmltble_appendBoxPrefix( rNamePrefix, nCol, nRow, bTop ) );
452 24 : if ( i != aFormatList.end() ) ++i;
453 24 : aFormatList.insert( i, &rFrameFormat );
454 : }
455 :
456 175 : return bInsert;
457 : }
458 :
459 26 : class SwXMLTableInfo_Impl
460 : {
461 : const SwTable *m_pTable;
462 : Reference<XTextSection> m_xBaseSection;
463 : bool m_bBaseSectionValid;
464 : sal_uInt32 m_nPrefix;
465 :
466 : public:
467 :
468 : inline SwXMLTableInfo_Impl( const SwTable *pTable, sal_uInt16 nPrefix );
469 :
470 343 : const SwTable *GetTable() const { return m_pTable; }
471 343 : const SwFrameFormat *GetTableFormat() const { return m_pTable->GetFrameFormat(); }
472 :
473 343 : bool IsBaseSectionValid() const { return m_bBaseSectionValid; }
474 168 : const Reference<XTextSection>& GetBaseSection() const { return m_xBaseSection; }
475 : inline void SetBaseSection( const Reference < XTextSection >& rBase );
476 : /// The namespace (table or loext) that should be used for the elements.
477 258 : sal_uInt16 GetPrefix() const { return m_nPrefix; }
478 : };
479 :
480 26 : inline SwXMLTableInfo_Impl::SwXMLTableInfo_Impl(const SwTable *pTable, sal_uInt16 nPrefix) :
481 : m_pTable(pTable),
482 : m_bBaseSectionValid(false),
483 26 : m_nPrefix(nPrefix)
484 : {
485 26 : }
486 :
487 26 : inline void SwXMLTableInfo_Impl::SetBaseSection(
488 : const Reference < XTextSection >& rBaseSection )
489 : {
490 26 : m_xBaseSection = rBaseSection;
491 26 : m_bBaseSectionValid = true;
492 26 : }
493 :
494 53 : void SwXMLExport::ExportTableColumnStyle( const SwXMLTableColumn_Impl& rCol )
495 : {
496 : // <style:style ...>
497 53 : CheckAttrList();
498 :
499 : // style:name="..."
500 53 : bool bEncoded = false;
501 : AddAttribute( XML_NAMESPACE_STYLE, XML_NAME,
502 53 : EncodeStyleName( rCol.GetStyleName(), &bEncoded ) );
503 53 : if( bEncoded )
504 0 : AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, rCol.GetStyleName() );
505 :
506 : // style:family="table-column"
507 53 : AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, XML_TABLE_COLUMN );
508 :
509 : {
510 : SvXMLElementExport aElem( *this, XML_NAMESPACE_STYLE, XML_STYLE, true,
511 53 : true );
512 106 : OUStringBuffer sValue;
513 53 : if( rCol.GetWidthOpt() )
514 : {
515 53 : GetTwipUnitConverter().convertMeasureToXML( sValue,
516 106 : rCol.GetWidthOpt() );
517 : AddAttribute( XML_NAMESPACE_STYLE, XML_COLUMN_WIDTH,
518 53 : sValue.makeStringAndClear() );
519 : }
520 53 : if( rCol.GetRelWidth() )
521 : {
522 8 : sValue.append( (sal_Int32)rCol.GetRelWidth() );
523 8 : sValue.append( '*' );
524 : AddAttribute( XML_NAMESPACE_STYLE, XML_REL_COLUMN_WIDTH,
525 8 : sValue.makeStringAndClear() );
526 : }
527 :
528 : {
529 : SvXMLElementExport aElemExport( *this, XML_NAMESPACE_STYLE,
530 : XML_TABLE_COLUMN_PROPERTIES,
531 53 : true, true );
532 53 : }
533 : }
534 53 : }
535 :
536 14 : void SwXMLExport::ExportTableLinesAutoStyles( const SwTableLines& rLines,
537 : sal_uInt32 nAbsWidth, sal_uInt32 nBaseWidth,
538 : const OUString& rNamePrefix,
539 : SwXMLTableColumnsSortByWidth_Impl& rExpCols,
540 : SwXMLTableFrameFormatsSort_Impl& rExpRows,
541 : SwXMLTableFrameFormatsSort_Impl& rExpCells,
542 : SwXMLTableInfo_Impl& rTableInfo,
543 : bool bTop )
544 : {
545 : // pass 1: calculate columns
546 14 : SwXMLTableLines_Impl *pLines = new SwXMLTableLines_Impl( rLines );
547 14 : if( !pTableLines )
548 3 : pTableLines = new SwXMLTableLinesCache_Impl();
549 :
550 14 : pTableLines->push_back( pLines );
551 :
552 : // pass 2: export column styles
553 : {
554 14 : const SwXMLTableColumns_Impl& rCols = pLines->GetColumns();
555 14 : sal_uInt32 nCPos = 0U;
556 14 : const size_t nColumns = rCols.size();
557 67 : for( size_t nColumn=0U; nColumn<nColumns; ++nColumn )
558 : {
559 53 : SwXMLTableColumn_Impl *pColumn = rCols[nColumn];
560 :
561 53 : sal_uInt32 nOldCPos = nCPos;
562 53 : nCPos = pColumn->GetPos();
563 :
564 53 : sal_uInt32 nWidth = nCPos - nOldCPos;
565 :
566 : // If a base width is given, the table has either an automatic
567 : // or margin alignment, or an percentage width. In either case,
568 : // relative widths should be exported.
569 53 : if( nBaseWidth )
570 : {
571 8 : pColumn->SetRelWidth( nWidth );
572 : }
573 :
574 : // If an absolute width is given, the table either has a fixed
575 : // width, or the current width is known from the layout. In the
576 : // later case, a base width is set in addition and must be used
577 : // to "absoultize" the relative column width.
578 53 : if( nAbsWidth )
579 : {
580 53 : sal_uInt32 nColAbsWidth = nWidth;
581 53 : if( nBaseWidth )
582 : {
583 8 : nColAbsWidth *= nAbsWidth;
584 8 : nColAbsWidth += (nBaseWidth/2UL);
585 8 : nColAbsWidth /= nBaseWidth;
586 : }
587 53 : pColumn->SetWidthOpt( nColAbsWidth, false );
588 : }
589 :
590 53 : SwXMLTableColumnsSortByWidth_Impl::const_iterator it = rExpCols.find( pColumn );
591 53 : if( it != rExpCols.end() )
592 : {
593 0 : pColumn->SetStyleName( (*it)->GetStyleName() );
594 : }
595 : else
596 : {
597 53 : if( bTop )
598 : {
599 53 : OUString sTmp;
600 53 : sw_GetTableBoxColStr( nColumn, sTmp );
601 53 : pColumn->SetStyleName( rNamePrefix + "." + sTmp );
602 : }
603 : else
604 : {
605 0 : pColumn->SetStyleName( rNamePrefix + "." + OUString::number(nColumn + 1U) );
606 : }
607 53 : ExportTableColumnStyle( *pColumn );
608 53 : rExpCols.insert( pColumn );
609 : }
610 : }
611 : }
612 :
613 : // pass 3: export line/rows
614 14 : const size_t nLines = rLines.size();
615 58 : for( size_t nLine=0U; nLine<nLines; ++nLine )
616 : {
617 44 : SwTableLine *pLine = rLines[nLine];
618 :
619 44 : SwFrameFormat *pFrameFormat = pLine->GetFrameFormat();
620 44 : if( rExpRows.AddRow( *pFrameFormat, rNamePrefix, nLine ) )
621 20 : ExportFormat( *pFrameFormat, XML_TABLE_ROW );
622 :
623 44 : const SwTableBoxes& rBoxes = pLine->GetTabBoxes();
624 44 : const size_t nBoxes = rBoxes.size();
625 :
626 44 : sal_uInt32 nCPos = 0U;
627 44 : size_t nCol = 0U;
628 219 : for( size_t nBox=0U; nBox<nBoxes; nBox++ )
629 : {
630 175 : SwTableBox *pBox = rBoxes[nBox];
631 :
632 175 : if( nBox < nBoxes-1U )
633 131 : nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
634 : else
635 44 : nCPos = pLines->GetWidth();
636 :
637 : // Und ihren Index
638 175 : const size_t nOldCol = nCol;
639 175 : SwXMLTableColumn_Impl aCol( nCPos );
640 175 : SwXMLTableColumns_Impl::const_iterator it = pLines->GetColumns().find( &aCol );
641 : OSL_ENSURE( it != pLines->GetColumns().end(), "couldn't find column" );
642 175 : nCol = it - pLines->GetColumns().begin();
643 :
644 175 : const SwStartNode *pBoxSttNd = pBox->GetSttNd();
645 175 : if( pBoxSttNd )
646 : {
647 175 : SwFrameFormat *pFrameFormat2 = pBox->GetFrameFormat();
648 175 : if( rExpCells.AddCell( *pFrameFormat2, rNamePrefix, nOldCol, nLine,
649 175 : bTop) )
650 24 : ExportFormat( *pFrameFormat2, XML_TABLE_CELL );
651 :
652 : Reference < XCell > xCell = SwXCell::CreateXCell(
653 175 : const_cast<SwFrameFormat *>(rTableInfo.GetTableFormat()),
654 : pBox,
655 350 : const_cast<SwTable *>(rTableInfo.GetTable()) );
656 175 : if (xCell.is())
657 : {
658 175 : Reference < XText > xText( xCell, UNO_QUERY );
659 175 : if( !rTableInfo.IsBaseSectionValid() )
660 : {
661 : Reference<XPropertySet> xCellPropertySet( xCell,
662 14 : UNO_QUERY );
663 28 : Any aAny = xCellPropertySet->getPropertyValue("TextSection");
664 28 : Reference < XTextSection > xTextSection;
665 14 : aAny >>= xTextSection;
666 28 : rTableInfo.SetBaseSection( xTextSection );
667 : }
668 :
669 175 : const bool bExportContent = bool(getExportFlags() & SvXMLExportFlags::CONTENT );
670 175 : if ( !bExportContent )
671 : {
672 : // AUTOSTYLES - not needed anymore if we are currently exporting content.xml
673 : GetTextParagraphExport()->collectTextAutoStyles(
674 0 : xText, rTableInfo.GetBaseSection(), IsShowProgress() );
675 175 : }
676 : }
677 : else {
678 : OSL_FAIL("here should be a XCell");
679 175 : }
680 : }
681 : else
682 : {
683 0 : ExportTableLinesAutoStyles( pBox->GetTabLines(),
684 : nAbsWidth, nBaseWidth,
685 : lcl_xmltble_appendBoxPrefix( rNamePrefix,
686 : nOldCol, nLine, bTop ),
687 : rExpCols, rExpRows, rExpCells,
688 0 : rTableInfo );
689 : }
690 :
691 175 : nCol++;
692 175 : }
693 : }
694 14 : }
695 :
696 14 : void SwXMLExport::ExportTableAutoStyles( const SwTableNode& rTableNd )
697 : {
698 14 : const SwTable& rTable = rTableNd.GetTable();
699 14 : const SwFrameFormat *pTableFormat = rTable.GetFrameFormat();
700 :
701 14 : if( pTableFormat )
702 : {
703 14 : sal_Int16 eTabHoriOri = pTableFormat->GetHoriOrient().GetHoriOrient();
704 14 : const SwFormatFrmSize& rFrmSize = pTableFormat->GetFrmSize();
705 :
706 14 : sal_uInt32 nAbsWidth = rFrmSize.GetSize().Width();
707 14 : sal_uInt32 nBaseWidth = 0UL;
708 14 : sal_Int8 nPrcWidth = rFrmSize.GetWidthPercent();
709 :
710 14 : bool bFixAbsWidth = nPrcWidth != 0 || /*text::*/HoriOrientation::NONE == eTabHoriOri
711 28 : || /*text::*/HoriOrientation::FULL == eTabHoriOri;
712 14 : if( bFixAbsWidth )
713 : {
714 4 : nBaseWidth = nAbsWidth;
715 4 : nAbsWidth = pTableFormat->FindLayoutRect(true).Width();
716 : if( !nAbsWidth )
717 : {
718 : // TODO?
719 : }
720 : }
721 14 : ExportTableFormat( *pTableFormat, nAbsWidth );
722 :
723 14 : SwXMLTableColumnsSortByWidth_Impl aExpCols;
724 28 : SwXMLTableFrameFormatsSort_Impl aExpRows;
725 28 : SwXMLTableFrameFormatsSort_Impl aExpCells;
726 28 : SwXMLTableInfo_Impl aTableInfo( &rTable, XML_NAMESPACE_TABLE );
727 14 : ExportTableLinesAutoStyles( rTable.GetTabLines(), nAbsWidth, nBaseWidth,
728 : pTableFormat->GetName(), aExpCols, aExpRows, aExpCells,
729 42 : aTableInfo, true);
730 : }
731 14 : }
732 :
733 168 : void SwXMLExport::ExportTableBox( const SwTableBox& rBox,
734 : sal_uInt32 nColSpan,
735 : sal_uInt32 nRowSpan,
736 : SwXMLTableInfo_Impl& rTableInfo )
737 : {
738 168 : const SwStartNode *pBoxSttNd = rBox.GetSttNd();
739 168 : if( pBoxSttNd )
740 : {
741 168 : const SwFrameFormat *pFrameFormat = rBox.GetFrameFormat();
742 168 : if( pFrameFormat )
743 : {
744 168 : const OUString sName = pFrameFormat->GetName();
745 168 : if( !sName.isEmpty() )
746 : {
747 168 : AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, EncodeStyleName(sName) );
748 168 : }
749 : }
750 : }
751 :
752 168 : if( nRowSpan != 1 )
753 : {
754 : AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_ROWS_SPANNED,
755 0 : OUString::number(nRowSpan) );
756 : }
757 :
758 168 : if( nColSpan != 1 )
759 : {
760 : AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_SPANNED,
761 1 : OUString::number(nColSpan) );
762 : }
763 :
764 : {
765 168 : if( pBoxSttNd )
766 : {
767 : // start node -> normal cell
768 : // get cell range for table
769 168 : Reference<XCell> xCell = SwXCell::CreateXCell( const_cast<SwFrameFormat *>(rTableInfo.GetTableFormat()),
770 : const_cast<SwTableBox *>(&rBox),
771 336 : const_cast<SwTable *>(rTableInfo.GetTable()) );
772 :
773 168 : if (xCell.is())
774 : {
775 168 : Reference<XText> xText( xCell, UNO_QUERY );
776 :
777 : // get formula (and protection)
778 336 : const OUString sCellFormula = xCell->getFormula();
779 :
780 : // if this cell has a formula, export it
781 : // (with value and number format)
782 168 : if (!sCellFormula.isEmpty())
783 : {
784 : const OUString sQValue =
785 0 : GetNamespaceMap().GetQNameByKey(
786 0 : XML_NAMESPACE_OOOW, sCellFormula, false );
787 : // formula
788 0 : AddAttribute(XML_NAMESPACE_TABLE, XML_FORMULA, sQValue );
789 : }
790 :
791 : // value and format (if NumberFormat != -1)
792 : Reference<XPropertySet> xCellPropertySet(xCell,
793 336 : UNO_QUERY);
794 168 : if (xCellPropertySet.is())
795 : {
796 168 : sal_Int32 nNumberFormat = 0;
797 168 : Any aAny = xCellPropertySet->getPropertyValue(sNumberFormat);
798 168 : aAny >>= nNumberFormat;
799 :
800 168 : if (css::util::NumberFormat::TEXT == nNumberFormat)
801 : {
802 : // text format
803 : AddAttribute( XML_NAMESPACE_OFFICE,
804 168 : XML_VALUE_TYPE, XML_STRING );
805 : }
806 0 : else if ( (-1 != nNumberFormat) && !xText->getString().isEmpty() )
807 : {
808 : // number format key:
809 : // (export values only if cell contains text;)
810 : XMLNumberFormatAttributesExportHelper::
811 : SetNumberFormatAttributes(
812 0 : *this, nNumberFormat, xCell->getValue(),
813 0 : true );
814 : }
815 : // else: invalid key; ignore
816 :
817 : // cell protection
818 168 : aAny = xCellPropertySet->getPropertyValue(sIsProtected);
819 168 : if (*static_cast<sal_Bool const *>(aAny.getValue()))
820 : {
821 : AddAttribute( XML_NAMESPACE_TABLE, XML_PROTECTED,
822 0 : XML_TRUE );
823 : }
824 :
825 168 : if( !rTableInfo.IsBaseSectionValid() )
826 : {
827 12 : aAny = xCellPropertySet->getPropertyValue("TextSection");
828 12 : Reference < XTextSection > xTextSection;
829 12 : aAny >>= xTextSection;
830 12 : rTableInfo.SetBaseSection( xTextSection );
831 168 : }
832 : }
833 :
834 : // export cell element
835 168 : SvXMLElementExport aElem( *this, rTableInfo.GetPrefix(),
836 336 : XML_TABLE_CELL, true, true );
837 :
838 : // export cell content
839 : GetTextParagraphExport()->exportText( xText,
840 168 : rTableInfo.GetBaseSection(),
841 504 : IsShowProgress() );
842 : }
843 : else
844 : {
845 : OSL_FAIL("here should be a XCell");
846 0 : ClearAttrList();
847 168 : }
848 : }
849 : else
850 : {
851 : // no start node -> merged cells: export subtable in cell
852 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
853 0 : XML_TABLE_CELL, true, true );
854 : {
855 : AddAttribute( XML_NAMESPACE_TABLE, XML_IS_SUB_TABLE,
856 0 : GetXMLToken( XML_TRUE ) );
857 :
858 : SvXMLElementExport aElemExport( *this, XML_NAMESPACE_TABLE,
859 0 : XML_TABLE, true, true );
860 0 : ExportTableLines( rBox.GetTabLines(), rTableInfo );
861 0 : }
862 : }
863 : }
864 168 : }
865 :
866 40 : void SwXMLExport::ExportTableLine( const SwTableLine& rLine,
867 : const SwXMLTableLines_Impl& rLines,
868 : SwXMLTableInfo_Impl& rTableInfo )
869 : {
870 40 : if( rLine.hasSoftPageBreak() )
871 : {
872 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TEXT,
873 1 : XML_SOFT_PAGE_BREAK, true, true );
874 : }
875 40 : const SwFrameFormat *pFrameFormat = rLine.GetFrameFormat();
876 40 : if( pFrameFormat )
877 : {
878 40 : const OUString sName = pFrameFormat->GetName();
879 40 : if( !sName.isEmpty() )
880 : {
881 36 : AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME, EncodeStyleName(sName) );
882 40 : }
883 : }
884 :
885 : {
886 40 : SvXMLElementExport aElem( *this, rTableInfo.GetPrefix(), XML_TABLE_ROW, true, true );
887 40 : const SwTableBoxes& rBoxes = rLine.GetTabBoxes();
888 40 : const size_t nBoxes = rBoxes.size();
889 :
890 40 : sal_uInt32 nCPos = 0U;
891 40 : size_t nCol = 0U;
892 208 : for( size_t nBox=0U; nBox<nBoxes; ++nBox )
893 : {
894 168 : const SwTableBox *pBox = rBoxes[nBox];
895 :
896 : // NEW TABLES
897 168 : const long nRowSpan = pBox->getRowSpan();
898 168 : if( nRowSpan < 1 )
899 : {
900 0 : SvXMLElementExport aElem2( *this, rTableInfo.GetPrefix(),
901 : XML_COVERED_TABLE_CELL, true,
902 0 : false );
903 : }
904 :
905 168 : if( nBox < nBoxes-1U )
906 128 : nCPos = nCPos + SwWriteTable::GetBoxWidth( pBox );
907 : else
908 40 : nCPos = rLines.GetWidth();
909 :
910 : // Und ihren Index
911 168 : const size_t nOldCol = nCol;
912 168 : SwXMLTableColumn_Impl aCol( nCPos );
913 168 : SwXMLTableColumns_Impl::const_iterator it = rLines.GetColumns().find( &aCol );
914 : OSL_ENSURE( it != rLines.GetColumns().end(), "couldn't find column" );
915 168 : nCol = it - rLines.GetColumns().begin();
916 :
917 : // #i95726# - Some fault tolerance, if table is somehow corrupted.
918 168 : if ( nCol < nOldCol )
919 : {
920 : OSL_FAIL( "table and/or table information seems to be corrupted." );
921 : // NOTE: nOldCol is not necessarily a valid index into
922 : // GetColumns(), but that doesn't matter here
923 0 : nCol = nOldCol;
924 : }
925 :
926 168 : const sal_uInt32 nColSpan = nCol - nOldCol + 1U;
927 :
928 168 : if ( nRowSpan >= 1 )
929 168 : ExportTableBox( *pBox, nColSpan, static_cast< sal_uInt32 >(nRowSpan), rTableInfo );
930 :
931 169 : for( size_t i=nOldCol; i<nCol; ++i )
932 : {
933 1 : SvXMLElementExport aElemExport( *this, rTableInfo.GetPrefix(),
934 : XML_COVERED_TABLE_CELL, true,
935 1 : false );
936 1 : }
937 :
938 168 : nCol++;
939 208 : }
940 : }
941 40 : }
942 :
943 12 : void SwXMLExport::ExportTableLines( const SwTableLines& rLines,
944 : SwXMLTableInfo_Impl& rTableInfo,
945 : sal_uInt32 nHeaderRows )
946 : {
947 : OSL_ENSURE( pTableLines && !pTableLines->empty(),
948 : "SwXMLExport::ExportTableLines: table columns infos missing" );
949 12 : if( !pTableLines || pTableLines->empty() )
950 0 : return;
951 :
952 12 : SwXMLTableLines_Impl* pLines = NULL;
953 : size_t nInfoPos;
954 12 : for( nInfoPos=0; nInfoPos < pTableLines->size(); nInfoPos++ )
955 : {
956 12 : if( pTableLines->at( nInfoPos )->GetLines() == &rLines )
957 : {
958 12 : pLines = pTableLines->at( nInfoPos );
959 12 : break;
960 : }
961 : }
962 : OSL_ENSURE( pLines,
963 : "SwXMLExport::ExportTableLines: table columns info missing" );
964 : OSL_ENSURE( 0==nInfoPos,
965 : "SwXMLExport::ExportTableLines: table columns infos are unsorted" );
966 12 : if( !pLines )
967 0 : return;
968 :
969 12 : SwXMLTableLinesCache_Impl::iterator it = pTableLines->begin();
970 12 : advance( it, nInfoPos );
971 12 : pTableLines->erase( it );
972 :
973 12 : if( pTableLines->empty() )
974 : {
975 1 : delete pTableLines ;
976 1 : pTableLines = NULL;
977 : }
978 :
979 : // pass 2: export columns
980 12 : const SwXMLTableColumns_Impl& rCols = pLines->GetColumns();
981 12 : size_t nColumn = 0U;
982 12 : const size_t nColumns = rCols.size();
983 12 : sal_Int32 nColRep = 1;
984 12 : SwXMLTableColumn_Impl *pColumn = (nColumns > 0) ? rCols[0U] : 0;
985 73 : while( pColumn )
986 : {
987 49 : nColumn++;
988 : SwXMLTableColumn_Impl *pNextColumn =
989 49 : (nColumn < nColumns) ? rCols[nColumn] : 0;
990 86 : if( pNextColumn &&
991 37 : pNextColumn->GetStyleName() == pColumn->GetStyleName() )
992 : {
993 0 : nColRep++;
994 : }
995 : else
996 : {
997 : AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME,
998 49 : EncodeStyleName(pColumn->GetStyleName()) );
999 :
1000 49 : if( nColRep > 1 )
1001 : {
1002 : AddAttribute( XML_NAMESPACE_TABLE, XML_NUMBER_COLUMNS_REPEATED,
1003 0 : OUString::number(nColRep) );
1004 : }
1005 :
1006 : {
1007 49 : SvXMLElementExport aElem( *this, rTableInfo.GetPrefix(), XML_TABLE_COLUMN, true, true );
1008 : }
1009 :
1010 49 : nColRep = 1;
1011 : }
1012 49 : pColumn = pNextColumn;
1013 : }
1014 :
1015 : // pass 3: export line/rows
1016 12 : const size_t nLines = rLines.size();
1017 : // export header rows, if present
1018 12 : if( nHeaderRows > 0 )
1019 : {
1020 : SvXMLElementExport aElem( *this, XML_NAMESPACE_TABLE,
1021 0 : XML_TABLE_HEADER_ROWS, true, true );
1022 :
1023 : OSL_ENSURE( nHeaderRows <= nLines, "more headers then lines?" );
1024 0 : for( size_t nLine = 0U; nLine < nHeaderRows; ++nLine )
1025 0 : ExportTableLine( *(rLines[nLine]), *pLines, rTableInfo );
1026 : }
1027 : // export remaining rows
1028 52 : for( size_t nLine = nHeaderRows; nLine < nLines; ++nLine )
1029 : {
1030 40 : ExportTableLine( *(rLines[nLine]), *pLines, rTableInfo );
1031 : }
1032 :
1033 12 : delete pLines;
1034 : }
1035 :
1036 : static void lcl_xmltble_ClearName_Line( SwTableLine* pLine );
1037 :
1038 168 : static void lcl_xmltble_ClearName_Box( SwTableBox* pBox )
1039 : {
1040 168 : if( !pBox->GetSttNd() )
1041 : {
1042 0 : for( SwTableLine* pLine : pBox->GetTabLines() )
1043 0 : lcl_xmltble_ClearName_Line( pLine );
1044 : }
1045 : else
1046 : {
1047 168 : SwFrameFormat *pFrameFormat = pBox->GetFrameFormat();
1048 168 : if( pFrameFormat && !pFrameFormat->GetName().isEmpty() )
1049 168 : pFrameFormat->SetName( OUString() );
1050 : }
1051 168 : }
1052 :
1053 40 : void lcl_xmltble_ClearName_Line( SwTableLine* pLine )
1054 : {
1055 208 : for( SwTableBox* pBox : pLine->GetTabBoxes() )
1056 168 : lcl_xmltble_ClearName_Box( pBox );
1057 40 : }
1058 :
1059 12 : void SwXMLExport::ExportTable( const SwTableNode& rTableNd )
1060 : {
1061 12 : const SwTable& rTable = rTableNd.GetTable();
1062 12 : const SwFrameFormat *pTableFormat = rTable.GetFrameFormat();
1063 12 : if( pTableFormat && !pTableFormat->GetName().isEmpty() )
1064 : {
1065 12 : AddAttribute( XML_NAMESPACE_TABLE, XML_NAME, pTableFormat->GetName() );
1066 : AddAttribute( XML_NAMESPACE_TABLE, XML_STYLE_NAME,
1067 12 : EncodeStyleName( pTableFormat->GetName() ) );
1068 : }
1069 :
1070 12 : sal_uInt16 nPrefix = XML_NAMESPACE_TABLE;
1071 12 : if (const SwFrameFormat* pFlyFormat = rTableNd.GetFlyFormat())
1072 : {
1073 2 : std::set<const SwFrameFormat*> aTextBoxes = SwTextBoxHelper::findTextBoxes(rTableNd.GetDoc());
1074 2 : if (aTextBoxes.find(pFlyFormat) != aTextBoxes.end())
1075 2 : nPrefix = XML_NAMESPACE_LO_EXT;
1076 : }
1077 :
1078 : {
1079 12 : SvXMLElementExport aElem( *this, nPrefix, XML_TABLE, true, true );
1080 :
1081 : // export DDE source (if this is a DDE table)
1082 12 : if ( rTable.ISA(SwDDETable) )
1083 : {
1084 : // get DDE Field Type (contains the DDE connection)
1085 : const SwDDEFieldType* pDDEFieldType =
1086 0 : static_cast<const SwDDETable&>(rTable).GetDDEFieldType();
1087 :
1088 : // connection name
1089 : AddAttribute( XML_NAMESPACE_OFFICE, XML_NAME,
1090 0 : pDDEFieldType->GetName() );
1091 :
1092 : // DDE command
1093 0 : const OUString sCmd = pDDEFieldType->GetCmd();
1094 : AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION,
1095 0 : sCmd.getToken(0, sfx2::cTokenSeparator) );
1096 : AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_ITEM,
1097 0 : sCmd.getToken(1, sfx2::cTokenSeparator) );
1098 : AddAttribute( XML_NAMESPACE_OFFICE, XML_DDE_TOPIC,
1099 0 : sCmd.getToken(2, sfx2::cTokenSeparator) );
1100 :
1101 : // auto update
1102 0 : if (pDDEFieldType->GetType() == SfxLinkUpdateMode::ALWAYS)
1103 : {
1104 : AddAttribute( XML_NAMESPACE_OFFICE,
1105 0 : XML_AUTOMATIC_UPDATE, XML_TRUE );
1106 : }
1107 :
1108 : // DDE source element (always empty)
1109 : SvXMLElementExport aSource(*this, XML_NAMESPACE_OFFICE,
1110 0 : XML_DDE_SOURCE, true, false);
1111 : }
1112 :
1113 24 : SwXMLTableInfo_Impl aTableInfo( &rTable, nPrefix );
1114 12 : ExportTableLines( rTable.GetTabLines(), aTableInfo, rTable.GetRowsToRepeat() );
1115 :
1116 52 : for( SwTableLine *pLine : ((SwTable &)rTable).GetTabLines() )
1117 52 : lcl_xmltble_ClearName_Line( pLine );
1118 : }
1119 12 : }
1120 :
1121 26 : void SwXMLTextParagraphExport::exportTable(
1122 : const Reference < XTextContent > & rTextContent,
1123 : bool bAutoStyles, bool _bProgress )
1124 : {
1125 26 : bool bOldShowProgress = static_cast<SwXMLExport&>(GetExport()).IsShowProgress();
1126 26 : static_cast<SwXMLExport&>(GetExport()).SetShowProgress( _bProgress );
1127 :
1128 26 : Reference < XTextTable > xTextTable( rTextContent, UNO_QUERY );
1129 : OSL_ENSURE( xTextTable.is(), "text table missing" );
1130 26 : if( xTextTable.is() )
1131 : {
1132 26 : const SwXTextTable *pXTable = 0;
1133 26 : Reference<XUnoTunnel> xTableTunnel( rTextContent, UNO_QUERY);
1134 26 : if( xTableTunnel.is() )
1135 : {
1136 : pXTable = reinterpret_cast< SwXTextTable * >(
1137 26 : sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() )));
1138 : OSL_ENSURE( pXTable, "SwXTextTable missing" );
1139 : }
1140 26 : if( pXTable )
1141 : {
1142 26 : SwFrameFormat *pFormat = pXTable->GetFrameFormat();
1143 : OSL_ENSURE( pFormat, "table format missing" );
1144 26 : const SwTable *pTable = SwTable::FindTable( pFormat );
1145 : OSL_ENSURE( pTable, "table missing" );
1146 26 : const SwTableNode *pTableNd = pTable->GetTableNode();
1147 : OSL_ENSURE( pTableNd, "table node missing" );
1148 26 : if( bAutoStyles )
1149 : {
1150 14 : SwNodeIndex aIdx( *pTableNd );
1151 : // AUTOSTYLES: Optimization: Do not export table autostyle if
1152 : // we are currently exporting the content.xml stuff and
1153 : // the table is located in header/footer:
1154 : // During the flat XML export (used e.g. by .sdw-export)
1155 : // ALL flags are set at the same time.
1156 14 : const bool bExportStyles = bool( GetExport().getExportFlags() & SvXMLExportFlags::STYLES );
1157 14 : if ( bExportStyles || !pFormat->GetDoc()->IsInHeaderFooter( aIdx ) )
1158 14 : static_cast<SwXMLExport&>(GetExport()).ExportTableAutoStyles( *pTableNd );
1159 : }
1160 : else
1161 : {
1162 12 : static_cast<SwXMLExport&>(GetExport()).ExportTable( *pTableNd );
1163 : }
1164 26 : }
1165 : }
1166 :
1167 26 : static_cast<SwXMLExport&>(GetExport()).SetShowProgress( bOldShowProgress );
1168 26 : }
1169 :
1170 286 : void SwXMLExport::DeleteTableLines()
1171 : {
1172 286 : if ( pTableLines )
1173 : {
1174 4 : for ( size_t i = 0, n = pTableLines->size(); i < n; ++i )
1175 2 : delete pTableLines->at( i );
1176 2 : pTableLines->clear();
1177 2 : delete pTableLines;
1178 : }
1179 463 : }
1180 :
1181 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|