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