LibreOffice Module sw (master)  1
xmltbli.cxx
Go to the documentation of this file.
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 <hintids.hxx>
21 
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/text/XTextTable.hpp>
26 #include <com/sun/star/table/XCellRange.hpp>
28 #include <o3tl/numeric.hxx>
29 #include <o3tl/safeint.hxx>
30 #include <sal/log.hxx>
31 #include <svl/itemset.hxx>
32 #include <svl/numformat.hxx>
33 #include <svl/zformat.hxx>
34 #include <sax/tools/converter.hxx>
35 #include <unotools/configmgr.hxx>
36 #include <xmloff/xmlnamespace.hxx>
37 #include <xmloff/namespacemap.hxx>
38 
39 #include <xmloff/families.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <xmloff/i18nmap.hxx>
42 #include <editeng/protitem.hxx>
43 #include <editeng/lrspitem.hxx>
44 #include <poolfmt.hxx>
45 #include <fmtfsize.hxx>
46 #include <fmtornt.hxx>
47 #include <fmtfordr.hxx>
48 #include <doc.hxx>
52 #include <swtable.hxx>
53 #include <swtblfmt.hxx>
54 #include <pam.hxx>
55 #include <unotbl.hxx>
56 #include <unotextrange.hxx>
57 #include <cellatr.hxx>
58 #include <swddetbl.hxx>
59 #include <ddefld.hxx>
60 #include <sfx2/linkmgr.hxx>
61 #include "xmlimp.hxx"
62 #include "xmltbli.hxx"
63 #include <vcl/svapp.hxx>
64 #include <ndtxt.hxx>
65 #include <SwStyleNameMapper.hxx>
66 
67 #include <algorithm>
68 #include <vector>
69 #include <memory>
70 
71 #include <limits.h>
72 
73 
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::uno;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::text;
78 using namespace ::com::sun::star::table;
79 using namespace ::com::sun::star::xml::sax;
80 using namespace ::xmloff::token;
81 
83 {
84  OUString m_aStyleName;
85 
86  OUString m_StringValue;
87 
88  OUString m_sFormula; // cell formula; valid if length > 0
89  double m_dValue; // formula value
90 
92 
94  sal_uInt32 m_nRowSpan;
95  sal_uInt32 m_nColSpan;
96 
97  bool m_bProtected : 1;
98  bool m_bHasValue; // determines whether dValue attribute is valid
99  bool mbCovered;
101 
102 public:
103 
104  SwXMLTableCell_Impl( sal_uInt32 nRSpan=1, sal_uInt32 nCSpan=1 ) :
105  m_dValue( 0.0 ),
106  m_pStartNode( nullptr ),
107  m_nRowSpan( nRSpan ),
108  m_nColSpan( nCSpan ),
109  m_bProtected( false ),
110  m_bHasValue( false ),
111  mbCovered( false )
112  , m_bHasStringValue(false)
113  {}
114 
115  inline void Set( const OUString& rStyleName,
116  sal_uInt32 nRSpan, sal_uInt32 nCSpan,
117  const SwStartNode *pStNd, SwXMLTableContext *pTable,
118  bool bProtect,
119  const OUString* pFormula,
120  bool bHasValue,
121  bool bCovered,
122  double dVal,
123  OUString const*const pStringValue);
124 
125  bool IsUsed() const { return m_pStartNode!=nullptr ||
126  m_xSubTable.is() || m_bProtected;}
127 
128  sal_uInt32 GetRowSpan() const { return m_nRowSpan; }
129  void SetRowSpan( sal_uInt32 nSet ) { m_nRowSpan = nSet; }
130  sal_uInt32 GetColSpan() const { return m_nColSpan; }
131  void SetStyleName(const OUString& rStyleName) { m_aStyleName = rStyleName; }
132  const OUString& GetStyleName() const { return m_aStyleName; }
133  const OUString& GetFormula() const { return m_sFormula; }
134  double GetValue() const { return m_dValue; }
135  bool HasValue() const { return m_bHasValue; }
136  bool IsProtected() const { return m_bProtected; }
137  bool IsCovered() const { return mbCovered; }
138  bool HasStringValue() const { return m_bHasStringValue; }
139  OUString const* GetStringValue() const {
140  return m_bHasStringValue ? &m_StringValue : nullptr;
141  }
142 
143  const SwStartNode *GetStartNode() const { return m_pStartNode; }
144  inline void SetStartNode( const SwStartNode *pSttNd );
145 
146  inline SwXMLTableContext *GetSubTable() const;
147 
148  inline void Dispose();
149 };
150 
151 inline void SwXMLTableCell_Impl::Set( const OUString& rStyleName,
152  sal_uInt32 nRSpan, sal_uInt32 nCSpan,
153  const SwStartNode *pStNd,
154  SwXMLTableContext *pTable,
155  bool bProtect,
156  const OUString* pFormula,
157  bool bHasVal,
158  bool bCov,
159  double dVal,
160  OUString const*const pStringValue )
161 {
162  m_aStyleName = rStyleName;
163  m_nRowSpan = nRSpan;
164  m_nColSpan = nCSpan;
165  m_pStartNode = pStNd;
166  m_xSubTable = pTable;
167  m_dValue = dVal;
168  m_bHasValue = bHasVal;
169  mbCovered = bCov;
170  if (pStringValue)
171  {
172  m_StringValue = *pStringValue;
173  }
174  m_bHasStringValue = (pStringValue != nullptr);
175  m_bProtected = bProtect;
176 
177  // set formula, if valid
178  if (pFormula != nullptr)
179  {
180  m_sFormula = *pFormula;
181  }
182 }
183 
184 inline void SwXMLTableCell_Impl::SetStartNode( const SwStartNode *pSttNd )
185 {
186  m_pStartNode = pSttNd;
187  m_xSubTable = nullptr;
188 }
189 
191 {
192  return static_cast<SwXMLTableContext *>(m_xSubTable.get());
193 }
194 
196 {
197  if( m_xSubTable.is() )
198  m_xSubTable = nullptr;
199 }
200 
202 {
203  OUString m_aStyleName;
205  std::vector<std::unique_ptr<SwXMLTableCell_Impl>> m_Cells;
207 
208 public:
209 
210  SwXMLTableRow_Impl( const OUString& rStyleName, sal_uInt32 nCells,
211  const OUString *pDfltCellStyleName = nullptr );
212 
213  inline SwXMLTableCell_Impl *GetCell( sal_uInt32 nCol );
214 
215  inline void Set( const OUString& rStyleName,
216  const OUString& rDfltCellStyleName );
217 
218  void Expand( sal_uInt32 nCells, bool bOneCell );
219 
220  void SetSplitable( bool bSet ) { m_bSplitable = bSet; }
221  bool IsSplitable() const { return m_bSplitable; }
222 
223  const OUString& GetStyleName() const { return m_aStyleName; }
224  const OUString& GetDefaultCellStyleName() const { return m_aDefaultCellStyleName; }
225 
226  void Dispose();
227 };
228 
229 SwXMLTableRow_Impl::SwXMLTableRow_Impl( const OUString& rStyleName,
230  sal_uInt32 nCells,
231  const OUString *pDfltCellStyleName ) :
232  m_aStyleName( rStyleName ),
233  m_bSplitable( false )
234 {
235  if( pDfltCellStyleName )
236  m_aDefaultCellStyleName = *pDfltCellStyleName;
237  OSL_ENSURE( nCells <= USHRT_MAX,
238  "SwXMLTableRow_Impl::SwXMLTableRow_Impl: too many cells" );
239  if( nCells > USHRT_MAX )
240  nCells = USHRT_MAX;
241 
242  for( sal_uInt32 i=0U; i<nCells; ++i )
243  {
244  m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>());
245  }
246 }
247 
249 {
250  OSL_ENSURE( nCol < USHRT_MAX,
251  "SwXMLTableRow_Impl::GetCell: column number is too big" );
252  // #i95726# - some fault tolerance
253  OSL_ENSURE( nCol < m_Cells.size(),
254  "SwXMLTableRow_Impl::GetCell: column number is out of bound" );
255  return nCol < m_Cells.size() ? m_Cells[nCol].get() : nullptr;
256 }
257 
258 void SwXMLTableRow_Impl::Expand( sal_uInt32 nCells, bool bOneCell )
259 {
260  OSL_ENSURE( nCells <= USHRT_MAX,
261  "SwXMLTableRow_Impl::Expand: too many cells" );
262  if( nCells > USHRT_MAX )
263  nCells = USHRT_MAX;
264 
265  sal_uInt32 nColSpan = nCells - m_Cells.size();
266  for (size_t i = m_Cells.size(); i < nCells; ++i)
267  {
268  m_Cells.push_back(std::make_unique<SwXMLTableCell_Impl>(
269  1UL, bOneCell ? nColSpan : 1UL));
270  nColSpan--;
271  }
272 
273  OSL_ENSURE( nCells <= m_Cells.size(),
274  "SwXMLTableRow_Impl::Expand: wrong number of cells" );
275 }
276 
277 inline void SwXMLTableRow_Impl::Set( const OUString& rStyleName,
278  const OUString& rDfltCellStyleName )
279 {
280  m_aStyleName = rStyleName;
281  m_aDefaultCellStyleName = rDfltCellStyleName;
282 }
283 
285 {
286  for (auto & pCell : m_Cells)
287  {
288  pCell->Dispose();
289  }
290 }
291 
292 namespace {
293 
294 class SwXMLTableCellContext_Impl : public SvXMLImportContext
295 {
296  OUString m_aStyleName;
297  OUString m_sFormula;
298  OUString m_sSaveParaDefault;
299  OUString m_StringValue;
300 
301  SvXMLImportContextRef m_xMyTable;
302 
303  double m_fValue;
304  bool m_bHasValue;
305  bool m_bHasStringValue;
306  bool m_bValueTypeIsString;
307  bool m_bProtect;
308 
309  sal_uInt32 m_nRowSpan;
310  sal_uInt32 m_nColSpan;
311  sal_uInt32 m_nColRepeat;
312 
313  bool m_bHasTextContent : 1;
314  bool m_bHasTableContent : 1;
315 
316  SwXMLTableContext *GetTable() { return static_cast<SwXMLTableContext *>(m_xMyTable.get()); }
317 
318  bool HasContent() const { return m_bHasTextContent || m_bHasTableContent; }
319  inline void InsertContent_();
320  inline void InsertContent();
321  inline void InsertContent( SwXMLTableContext *pTable );
322 
323 public:
324 
325  SwXMLTableCellContext_Impl(
326  SwXMLImport& rImport, sal_Int32 nElement,
327  const Reference< xml::sax::XFastAttributeList > & xAttrList,
328  SwXMLTableContext *pTable );
329 
330  virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
331  sal_Int32 nElement,
332  const Reference< xml::sax::XFastAttributeList > & xAttrList ) override;
333  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
334 
335  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
336 };
337 
339 class SwXMLCoveredTableCellContext : public SvXMLImportContext
340 {
341 public:
342  SwXMLCoveredTableCellContext(SwXMLImport& rImport,
343  const Reference<xml::sax::XFastAttributeList>& xAttrList,
344  SwXMLTableContext& rTable);
345 };
346 
347 SwXMLCoveredTableCellContext::SwXMLCoveredTableCellContext(
348  SwXMLImport& rImport, const Reference<xml::sax::XFastAttributeList>& xAttrList,
349  SwXMLTableContext& rTable)
350  : SvXMLImportContext(rImport)
351 {
352  OUString aStyleName;
353  for (auto& rIter : sax_fastparser::castToFastAttributeList(xAttrList))
354  {
355  switch (rIter.getToken())
356  {
357  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
358  aStyleName = rIter.toString();
359  break;
360  }
361  }
362 
363  if (!aStyleName.isEmpty())
364  {
365  rTable.InsertCoveredCell(aStyleName);
366  }
367 }
368 }
369 
370 SwXMLTableCellContext_Impl::SwXMLTableCellContext_Impl(
371  SwXMLImport& rImport, sal_Int32 /*nElement*/,
372  const Reference< xml::sax::XFastAttributeList > & xAttrList,
373  SwXMLTableContext *pTable ) :
374  SvXMLImportContext( rImport ),
375  m_xMyTable( pTable ),
376  m_fValue( 0.0 ),
377  m_bHasValue( false ),
378  m_bHasStringValue(false),
379  m_bValueTypeIsString(false),
380  m_bProtect( false ),
381  m_nRowSpan( 1 ),
382  m_nColSpan( 1 ),
383  m_nColRepeat( 1 ),
384  m_bHasTextContent( false ),
385  m_bHasTableContent( false )
386 {
387  m_sSaveParaDefault = GetImport().GetTextImport()->GetCellParaStyleDefault();
388  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
389  {
390  switch( aIter.getToken() )
391  {
392  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
393  m_aStyleName = aIter.toString();
394  GetImport().GetTextImport()->SetCellParaStyleDefault(m_aStyleName);
395  break;
396  case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED):
397  m_nColSpan = static_cast<sal_uInt32>(std::max<sal_Int32>(1, aIter.toInt32()));
398  if (m_nColSpan > 256)
399  {
400  SAL_INFO("sw.xml", "ignoring huge table:number-columns-spanned " << m_nColSpan);
401  m_nColSpan = 1;
402  }
403  break;
404  case XML_ELEMENT(TABLE, XML_NUMBER_ROWS_SPANNED):
405  m_nRowSpan = static_cast<sal_uInt32>(std::max<sal_Int32>(1, aIter.toInt32()));
406  if (m_nRowSpan > 8192 || (m_nRowSpan > 256 && utl::ConfigManager::IsFuzzing()))
407  {
408  SAL_INFO("sw.xml", "ignoring huge table:number-rows-spanned " << m_nRowSpan);
409  m_nRowSpan = 1;
410  }
411  break;
412  case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
413  m_nColRepeat = static_cast<sal_uInt32>(std::max<sal_Int32>(1, aIter.toInt32()));
414  if (m_nColRepeat > 256)
415  {
416  SAL_INFO("sw.xml", "ignoring huge table:number-columns-repeated " << m_nColRepeat);
417  m_nColRepeat = 1;
418  }
419  break;
420  case XML_ELEMENT(TABLE, XML_FORMULA):
421  {
422  OUString sTmp;
423  const sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().
424  GetKeyByAttrValueQName(aIter.toString(), &sTmp);
425  m_sFormula = XML_NAMESPACE_OOOW == nPrefix2 ? sTmp : aIter.toString();
426  }
427  break;
428  case XML_ELEMENT(OFFICE, XML_VALUE):
429  {
430  // Writer wrongly uses DBL_MAX to flag error but fails to
431  // check for it after import, so check that here, tdf#139126.
432  double fTmp;
433  if (::sax::Converter::convertDouble(fTmp, aIter.toView()) && fTmp < DBL_MAX)
434  {
435  m_fValue = fTmp;
436  m_bHasValue = true;
437  }
438  }
439  break;
440  case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
441  {
442  double fTmp;
443  if (::sax::Converter::convertDuration(fTmp, aIter.toView()))
444  {
445  m_fValue = fTmp;
446  m_bHasValue = true;
447  }
448  }
449  break;
450  case XML_ELEMENT(OFFICE, XML_DATE_VALUE):
451  {
452  double fTmp;
453  if (GetImport().GetMM100UnitConverter().convertDateTime(fTmp,
454  aIter.toView()))
455  {
456  m_fValue = fTmp;
457  m_bHasValue = true;
458  }
459  }
460  break;
461  case XML_ELEMENT(OFFICE, XML_BOOLEAN_VALUE):
462  {
463  bool bTmp(false);
464  if (::sax::Converter::convertBool(bTmp, aIter.toView()))
465  {
466  m_fValue = (bTmp ? 1.0 : 0.0);
467  m_bHasValue = true;
468  }
469  }
470  break;
471  case XML_ELEMENT(TABLE, XML_PROTECT): // for backwards compatibility with SRC629 (and before)
473  {
474  bool bTmp(false);
475  if (::sax::Converter::convertBool(bTmp, aIter.toView()))
476  {
477  m_bProtect = bTmp;
478  }
479  }
480  break;
481  case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
482  {
483  m_StringValue = aIter.toString();
484  m_bHasStringValue = true;
485  }
486  break;
487  case XML_ELEMENT(OFFICE, XML_VALUE_TYPE):
488  {
489  if ("string" == aIter.toView())
490  {
491  m_bValueTypeIsString = true;
492  }
493  // ignore other types - it would be correct to require
494  // matching value-type and $type-value attributes,
495  // but we've been reading those without checking forever.
496  }
497  break;
498  default:
499  SAL_WARN("sw", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << aIter.toString());
500  }
501  }
502 }
503 
504 inline void SwXMLTableCellContext_Impl::InsertContent_()
505 {
506  SwStartNode const*const pStartNode( GetTable()->InsertTableSection(nullptr,
507  (m_bHasStringValue && m_bValueTypeIsString &&
508  !m_aStyleName.isEmpty()) ? & m_aStyleName : nullptr) );
509  GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan,
510  pStartNode,
511  nullptr, m_bProtect, &m_sFormula, m_bHasValue, m_fValue,
512  (m_bHasStringValue && m_bValueTypeIsString) ? &m_StringValue : nullptr);
513 }
514 
515 inline void SwXMLTableCellContext_Impl::InsertContent()
516 {
517  OSL_ENSURE( !HasContent(), "content already there" );
518  m_bHasTextContent = true;
519  InsertContent_();
520 }
521 
522 inline void SwXMLTableCellContext_Impl::InsertContent(
523  SwXMLTableContext *pTable )
524 {
525  GetTable()->InsertCell( m_aStyleName, m_nRowSpan, m_nColSpan, nullptr, pTable, m_bProtect );
526  m_bHasTableContent = true;
527 }
528 
529 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableCellContext_Impl::createFastChildContext(
530  sal_Int32 nElement,
531  const Reference< xml::sax::XFastAttributeList > & xAttrList )
532 {
533  SvXMLImportContext *pContext = nullptr;
534 
535  bool bSubTable = false;
536  if( nElement == XML_ELEMENT(TABLE, XML_TABLE) )
537  {
538  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
539  {
540  if( aIter.getToken() == XML_ELEMENT(TABLE, XML_IS_SUB_TABLE) )
541  {
542  if ( IsXMLToken( aIter, XML_TRUE ) )
543  bSubTable = true;
544  }
545  else
546  XMLOFF_WARN_UNKNOWN("sw", aIter);
547  //FIXME: RDFa
548  }
549  }
550 
551  if( bSubTable )
552  {
553  if( !HasContent() )
554  {
555  SwXMLTableContext *pTableContext =
556  new SwXMLTableContext( GetSwImport(), GetTable() );
557  pContext = pTableContext;
558  if( GetTable()->IsValid() )
559  InsertContent( pTableContext );
560 
561  GetTable()->SetHasSubTables( true );
562  }
563  }
564  else
565  {
566  if( GetTable()->IsValid() && !HasContent() )
567  InsertContent();
568  // fdo#60842: "office:string-value" overrides text content -> no import
569  if (!(m_bValueTypeIsString && m_bHasStringValue))
570  {
571  pContext = GetImport().GetTextImport()->CreateTextChildContext(
572  GetImport(), nElement, xAttrList,
573  XMLTextType::Cell );
574  }
575  }
576 
577  return pContext;
578 }
579 
580 void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
581 {
582  if( GetTable()->IsValid() )
583  {
584  if( m_bHasTextContent )
585  {
586  GetImport().GetTextImport()->DeleteParagraph();
587  if( m_nColRepeat > 1 && m_nColSpan == 1 )
588  {
589  // The original text is invalid after deleting the last
590  // paragraph
591  Reference < XTextCursor > xSrcTextCursor =
592  GetImport().GetTextImport()->GetText()->createTextCursor();
593  xSrcTextCursor->gotoEnd( true );
594 
595  // Until we have an API for copying we have to use the core.
596  Reference<XUnoTunnel> xSrcCursorTunnel( xSrcTextCursor, UNO_QUERY);
597  assert(xSrcCursorTunnel.is() && "missing XUnoTunnel for Cursor");
598  OTextCursorHelper *pSrcTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xSrcTextCursor);
599  assert(pSrcTextCursor && "SwXTextCursor missing");
600  SwDoc *pDoc = pSrcTextCursor->GetDoc();
601  const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM();
602 
603  while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
604  {
605  InsertContent_();
606 
607  Reference<XUnoTunnel> xDstCursorTunnel(
608  GetImport().GetTextImport()->GetCursor(), UNO_QUERY);
609  assert(xDstCursorTunnel.is() && "missing XUnoTunnel for Cursor");
610  OTextCursorHelper *pDstTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(GetImport().GetTextImport()->GetCursor());
611  assert(pDstTextCursor && "SwXTextCursor missing");
612  SwPaM aSrcPaM(*pSrcPaM->GetMark(), *pSrcPaM->GetPoint());
613  SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() );
615 
616  m_nColRepeat--;
617  }
618  }
619  }
620  else if( !m_bHasTableContent )
621  {
622  InsertContent();
623  if( m_nColRepeat > 1 && m_nColSpan == 1 )
624  {
625  while( m_nColRepeat > 1 && GetTable()->IsInsertCellPossible() )
626  {
627  InsertContent_();
628  m_nColRepeat--;
629  }
630  }
631  }
632  }
633  GetImport().GetTextImport()->SetCellParaStyleDefault(m_sSaveParaDefault);
634 }
635 
636 namespace {
637 
638 class SwXMLTableColContext_Impl : public SvXMLImportContext
639 {
640  SvXMLImportContextRef m_xMyTable;
641 
642  SwXMLTableContext *GetTable() { return static_cast<SwXMLTableContext *>(m_xMyTable.get()); }
643 
644 public:
645 
646  SwXMLTableColContext_Impl(
647  SwXMLImport& rImport,
648  const Reference< xml::sax::XFastAttributeList > & xAttrList,
649  SwXMLTableContext *pTable );
650 
651  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
652 };
653 
654 }
655 
656 SwXMLTableColContext_Impl::SwXMLTableColContext_Impl(
657  SwXMLImport& rImport,
658  const Reference< xml::sax::XFastAttributeList > & xAttrList,
659  SwXMLTableContext *pTable ) :
660  SvXMLImportContext( rImport ),
661  m_xMyTable( pTable )
662 {
663  sal_uInt32 nColRep = 1;
664  OUString aStyleName, aDfltCellStyleName;
665 
666  for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
667  {
668  switch (aIter.getToken())
669  {
670  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
671  aStyleName = aIter.toString();
672  break;
673  case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED):
674  {
675  nColRep = static_cast<sal_uInt32>(std::max<sal_Int32>(1, aIter.toInt32()));
676  if (nColRep > 256)
677  {
678  SAL_INFO("sw.xml", "ignoring huge table:number-columns-repeated " << nColRep);
679  nColRep = 1;
680  }
681  break;
682  }
683  case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
684  aDfltCellStyleName = aIter.toString();
685  break;
686  case XML_ELEMENT(XML, XML_ID):
687  {
688  //FIXME where to put this??? columns do not actually exist in writer...
689  break;
690  }
691  default:
692  XMLOFF_WARN_UNKNOWN("sw", aIter);
693  }
694  }
695 
696  sal_Int32 nWidth = MINLAY;
697  bool bRelWidth = true;
698  if( !aStyleName.isEmpty() )
699  {
700  const SwFormatFrameSize *pSize;
701  const SfxItemSet *pAutoItemSet = nullptr;
702  if( GetSwImport().FindAutomaticStyle(
703  XmlStyleFamily::TABLE_COLUMN,
704  aStyleName, &pAutoItemSet ) &&
705  pAutoItemSet &&
706  (pSize = pAutoItemSet->GetItemIfSet( RES_FRM_SIZE, false )) )
707  {
708  nWidth = pSize->GetWidth();
709  bRelWidth = SwFrameSize::Variable == pSize->GetHeightSizeType();
710  }
711  }
712 
713  if( nWidth )
714  {
715  while( nColRep-- && GetTable()->IsInsertColPossible() )
716  GetTable()->InsertColumn( nWidth, bRelWidth, &aDfltCellStyleName );
717  }
718 }
719 
720 namespace {
721 
722 class SwXMLTableColsContext_Impl : public SvXMLImportContext
723 {
724  SvXMLImportContextRef m_xMyTable;
725 
726  SwXMLTableContext *GetTable() { return static_cast<SwXMLTableContext *>(m_xMyTable.get()); }
727 
728 public:
729 
730  SwXMLTableColsContext_Impl(
731  SwXMLImport& rImport,
732  SwXMLTableContext *pTable );
733 
734  virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
735  sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList ) override;
736 
737  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
738 };
739 
740 }
741 
742 SwXMLTableColsContext_Impl::SwXMLTableColsContext_Impl(
743  SwXMLImport& rImport,
744  SwXMLTableContext *pTable ) :
745  SvXMLImportContext( rImport ),
746  m_xMyTable( pTable )
747 {
748 }
749 
750 css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTableColsContext_Impl::createFastChildContext(
751  sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList )
752 {
753  SvXMLImportContext *pContext = nullptr;
754 
755  if( nElement == XML_ELEMENT(TABLE, XML_TABLE_COLUMN) &&
756  GetTable()->IsInsertColPossible() )
757  pContext = new SwXMLTableColContext_Impl( GetSwImport(), xAttrList, GetTable() );
758  else
759  XMLOFF_WARN_UNKNOWN_ELEMENT("sw", nElement);
760 
761  return pContext;
762 }
763 
764 namespace {
765 
766 class SwXMLTableRowContext_Impl : public SvXMLImportContext
767 {
768  SvXMLImportContextRef m_xMyTable;
769 
770  sal_uInt32 m_nRowRepeat;
771 
772  SwXMLTableContext *GetTable() { return static_cast<SwXMLTableContext *>(m_xMyTable.get()); }
773 
774 public:
775 
776  SwXMLTableRowContext_Impl(
777  SwXMLImport& rImport, sal_Int32 nElement,
778  const Reference< xml::sax::XFastAttributeList > & xAttrList,
779  SwXMLTableContext *pTable, bool bInHead=false );
780 
781  virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext( sal_Int32 nElement,
782  const Reference< xml::sax::XFastAttributeList > & xAttrList ) override;
783 
784  virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
785 
786  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
787 };
788 
789 }
790 
791 SwXMLTableRowContext_Impl::SwXMLTableRowContext_Impl( SwXMLImport& rImport,
792  sal_Int32 /*nElement*/,
793  const Reference< xml::sax::XFastAttributeList > & xAttrList,
794  SwXMLTableContext *pTable,
795  bool bInHead ) :
796  SvXMLImportContext( rImport ),
797  m_xMyTable( pTable ),
798  m_nRowRepeat( 1 )
799 {
800  OUString aStyleName, aDfltCellStyleName;
801 
802  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
803  {
804  switch(aIter.getToken())
805  {
806  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
807  aStyleName = aIter.toString();
808  break;
809  case XML_ELEMENT(STYLE, XML_NUMBER_ROWS_REPEATED):
810  {
811  m_nRowRepeat = static_cast<sal_uInt32>(std::max<sal_Int32>(1, aIter.toInt32()));
812  if (m_nRowRepeat > 8192 || (m_nRowRepeat > 256 && utl::ConfigManager::IsFuzzing()))
813  {
814  SAL_INFO("sw.xml", "ignoring huge table:number-rows-repeated " << m_nRowRepeat);
815  m_nRowRepeat = 1;
816  }
817  break;
818  }
819  case XML_ELEMENT(STYLE, XML_DEFAULT_CELL_STYLE_NAME):
820  aDfltCellStyleName = aIter.toString();
821  break;
822  case XML_ELEMENT(XML, XML_ID):
823  break;
824  default:
825  XMLOFF_WARN_UNKNOWN("sw", aIter);
826  }
827  }
828  if( GetTable()->IsValid() )
829  GetTable()->InsertRow( aStyleName, aDfltCellStyleName, bInHead );
830 }
831 
832 void SwXMLTableRowContext_Impl::endFastElement(sal_Int32 )
833 {
834  if( GetTable()->IsValid() )
835  {
836  GetTable()->FinishRow();
837 
838  if( m_nRowRepeat > 1 )
839  GetTable()->InsertRepRows( m_nRowRepeat );
840  }
841 }
842 
843 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowContext_Impl::createFastChildContext(
844  sal_Int32 nElement,
845  const Reference< xml::sax::XFastAttributeList > & xAttrList )
846 {
847  SvXMLImportContext *pContext = nullptr;
848 
849  if( nElement == XML_ELEMENT(TABLE, XML_TABLE_CELL) ||
850  nElement == XML_ELEMENT(LO_EXT, XML_TABLE_CELL) )
851  {
852  if( !GetTable()->IsValid() || GetTable()->IsInsertCellPossible() )
853  pContext = new SwXMLTableCellContext_Impl( GetSwImport(), nElement,
854  xAttrList,
855  GetTable() );
856  }
857  else if( nElement == XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL) ||
858  nElement == XML_ELEMENT(LO_EXT, XML_COVERED_TABLE_CELL) )
859  {
860  if (GetTable()->IsValid() && GetTable()->IsInsertCoveredCellPossible())
861  {
862  pContext = new SwXMLCoveredTableCellContext(GetSwImport(), xAttrList, *GetTable());
863  }
864  else
865  {
866  pContext = new SvXMLImportContext(GetImport());
867  }
868  }
869  else
870  SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
871 
872  return pContext;
873 }
874 
875 namespace {
876 
877 class SwXMLTableRowsContext_Impl : public SvXMLImportContext
878 {
879  SvXMLImportContextRef m_xMyTable;
880 
881  bool m_bHeader;
882 
883  SwXMLTableContext *GetTable() { return static_cast<SwXMLTableContext *>(m_xMyTable.get()); }
884 
885 public:
886 
887  SwXMLTableRowsContext_Impl( SwXMLImport& rImport,
888  SwXMLTableContext *pTable,
889  bool bHead );
890 
891  virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
892  sal_Int32 nElement,
893  const Reference< xml::sax::XFastAttributeList > & xAttrList ) override;
894 
895  SwXMLImport& GetSwImport() { return static_cast<SwXMLImport&>(GetImport()); }
896 };
897 
898 }
899 
900 SwXMLTableRowsContext_Impl::SwXMLTableRowsContext_Impl( SwXMLImport& rImport,
901  SwXMLTableContext *pTable,
902  bool bHead ) :
903  SvXMLImportContext( rImport ),
904  m_xMyTable( pTable ),
905  m_bHeader( bHead )
906 {
907 }
908 
909 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableRowsContext_Impl::createFastChildContext(
910  sal_Int32 nElement,
911  const Reference< xml::sax::XFastAttributeList > & xAttrList )
912 {
913  if( nElement== XML_ELEMENT(TABLE, XML_TABLE_ROW ) &&
914  GetTable()->IsInsertRowPossible() )
915  return new SwXMLTableRowContext_Impl( GetSwImport(), nElement,
916  xAttrList,
917  GetTable(),
918  m_bHeader );
919  SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement));
920  return nullptr;
921 }
922 
924 {
927  OUString m_sDDEItem;
928  OUString m_sDDETopic;
930 
931 public:
932 
933 
935 
936  virtual void SAL_CALL startFastElement(
937  sal_Int32 nElement,
938  const Reference<xml::sax::XFastAttributeList> & xAttrList) override;
939 
940  OUString& GetConnectionName() { return m_sConnectionName; }
941  OUString& GetDDEApplication() { return m_sDDEApplication; }
942  OUString& GetDDEItem() { return m_sDDEItem; }
943  OUString& GetDDETopic() { return m_sDDETopic; }
945 };
946 
947 
949  SvXMLImportContext(rImport),
950  m_bIsAutomaticUpdate(false)
951 {
952 }
953 
955  sal_Int32 /*nElement*/,
956  const Reference<xml::sax::XFastAttributeList> & xAttrList)
957 {
958  for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
959  {
960  switch (aIter.getToken())
961  {
963  m_sDDEApplication = aIter.toString();
964  break;
966  m_sDDETopic = aIter.toString();
967  break;
969  m_sDDEItem = aIter.toString();
970  break;
971  case XML_ELEMENT(OFFICE, XML_NAME):
972  m_sConnectionName = aIter.toString();
973  break;
975  {
976  bool bTmp(false);
977  if (::sax::Converter::convertBool(bTmp, aIter.toView()))
978  {
979  m_bIsAutomaticUpdate = bTmp;
980  }
981  break;
982  }
983  default:
984  XMLOFF_WARN_UNKNOWN("sw", aIter);
985  }
986  // else: unknown attribute namespace
987  }
988 }
989 
990 // generate a new name for DDE field type (called by lcl_GetDDEFieldType below)
991 static OUString lcl_GenerateFieldTypeName(const OUString& sPrefix, SwTableNode* pTableNode)
992 {
993  const OUString sPrefixStr(sPrefix.isEmpty() ? OUString("_") : sPrefix);
994 
995  // increase count until we find a name that is not yet taken
996  OUString sName;
997  sal_Int32 nCount = 0;
998  do
999  {
1000  // this is crazy, but just in case all names are taken: exit gracefully
1001  if (nCount == SAL_MAX_INT32)
1002  return sName;
1003 
1004  ++nCount;
1005  sName = sPrefixStr + OUString::number(nCount);
1006  }
1007  while (nullptr != pTableNode->GetDoc().getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Dde, sName, false));
1008 
1009  return sName;
1010 }
1011 
1012 // set table properties
1014  SwTableNode* pTableNode)
1015 {
1016  // make command string
1017  const OUString sCommand(pContext->GetDDEApplication()
1018  + OUStringChar(sfx2::cTokenSeparator)
1019  + pContext->GetDDEItem()
1020  + OUStringChar(sfx2::cTokenSeparator)
1021  + pContext->GetDDETopic());
1022 
1023  const SfxLinkUpdateMode nType = pContext->GetIsAutomaticUpdate()
1024  ? SfxLinkUpdateMode::ALWAYS
1025  : SfxLinkUpdateMode::ONCALL;
1026 
1027  OUString sName(pContext->GetConnectionName());
1028 
1029  // field type to be returned
1030  SwDDEFieldType* pType = nullptr;
1031 
1032  // valid name?
1033  if (sName.isEmpty())
1034  {
1036  pTableNode);
1037  }
1038  else
1039  {
1040  // check for existing DDE field type with the same name
1041  SwDDEFieldType* pOldType = static_cast<SwDDEFieldType*>(pTableNode->GetDoc().getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Dde, sName, false));
1042  if (nullptr != pOldType)
1043  {
1044  // same values -> return old type
1045  if ( (pOldType->GetCmd() == sCommand) &&
1046  (pOldType->GetType() == nType) )
1047  {
1048  // same name, same values -> return old type!
1049  pType = pOldType;
1050  }
1051  else
1052  {
1053  // same name, different values -> think of new name
1055  pTableNode);
1056  }
1057  }
1058  // no old type -> create new one
1059  }
1060 
1061  // create new field type (unless we already have one)
1062  if (nullptr == pType)
1063  {
1064  // create new field type and return
1065  SwDDEFieldType aDDEFieldType(sName, sCommand, nType);
1066  pType = static_cast<SwDDEFieldType*>(pTableNode->
1067  GetDoc().getIDocumentFieldsAccess().InsertFieldType(aDDEFieldType));
1068  }
1069 
1070  OSL_ENSURE(nullptr != pType, "We really want a SwDDEFieldType here!");
1071  return pType;
1072 }
1073 
1075 {
1076 public:
1077  OUString msName;
1078  sal_Int32 mnWidth;
1080 
1081  TableBoxIndex( const OUString& rName, sal_Int32 nWidth,
1082  bool bProtected ) :
1083  msName( rName ),
1084  mnWidth( nWidth ),
1085  mbProtected( bProtected )
1086  { }
1087 
1088  bool operator== ( const TableBoxIndex& rArg ) const
1089  {
1090  return (rArg.mnWidth == mnWidth) &&
1091  (rArg.mbProtected == mbProtected) &&
1092  (rArg.msName == msName);
1093  }
1094 };
1095 
1097 {
1098 public:
1099  size_t operator() (const TableBoxIndex& rArg) const
1100  {
1101  return rArg.msName.hashCode() + rArg.mnWidth + (rArg.mbProtected ? 1 : 0);
1102  }
1103 };
1104 
1106  sal_uInt32 nCol ) const
1107 {
1108  return (*m_pRows)[nRow]->GetCell( nCol );
1109 }
1110 
1112  sal_uInt32 nCol )
1113 {
1114  return (*m_pRows)[nRow]->GetCell( nCol );
1115 }
1116 
1117 
1119  const Reference< xml::sax::XFastAttributeList > & xAttrList ) :
1120  XMLTextTableContext( rImport ),
1121  m_pRows( new SwXMLTableRows_Impl ),
1122  m_pTableNode( nullptr ),
1123  m_pBox1( nullptr ),
1124  m_bOwnsBox1( false ),
1125  m_pSttNd1( nullptr ),
1126  m_pBoxFormat( nullptr ),
1127  m_pLineFormat( nullptr ),
1128  m_bFirstSection( true ),
1129  m_bRelWidth( true ),
1130  m_bHasSubTables( false ),
1131  m_nHeaderRows( 0 ),
1132  m_nCurRow( 0 ),
1133  m_nCurCol( 0 ),
1134  m_nNonMergedCurCol( 0 ),
1135  m_nWidth( 0 )
1136 {
1137  OUString aName;
1138  OUString sXmlId;
1139 
1140  // this method will modify the document directly -> lock SolarMutex
1141  SolarMutexGuard aGuard;
1142 
1143  for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
1144  {
1145  const OUString sValue = aIter.toString();
1146  switch(aIter.getToken())
1147  {
1148  case XML_ELEMENT(TABLE, XML_STYLE_NAME):
1149  m_aStyleName = sValue;
1150  break;
1151  case XML_ELEMENT(TABLE, XML_NAME):
1152  aName = sValue;
1153  break;
1154  case XML_ELEMENT(TABLE, XML_DEFAULT_CELL_STYLE_NAME):
1155  m_aDfltCellStyleName = sValue;
1156  break;
1157  case XML_ELEMENT(TABLE, XML_TEMPLATE_NAME):
1158  m_aTemplateName = sValue;
1159  break;
1160  case XML_ELEMENT(XML, XML_ID):
1161  sXmlId = sValue;
1162  break;
1163  default:
1164  XMLOFF_WARN_UNKNOWN("sw", aIter);
1165  }
1166  }
1167 
1169 
1170  OUString sTableName;
1171  if( !aName.isEmpty() )
1172  {
1173  const SwTableFormat *pTableFormat = pDoc->FindTableFormatByName( aName );
1174  if( !pTableFormat )
1175  sTableName = aName;
1176  }
1177  if( sTableName.isEmpty() )
1178  {
1179  sTableName = pDoc->GetUniqueTableName();
1181  ->GetRenameMap().Add( XML_TEXT_RENAME_TYPE_TABLE, aName, sTableName );
1182  }
1183 
1184  Reference< XTextTable > xTable;
1185  SwXTextTable *pXTable = nullptr;
1186  Reference<XMultiServiceFactory> xFactory( GetImport().GetModel(),
1187  UNO_QUERY );
1188  OSL_ENSURE( xFactory.is(), "factory missing" );
1189  if( xFactory.is() )
1190  {
1191  Reference<XInterface> xIfc = xFactory->createInstance( "com.sun.star.text.TextTable" );
1192  OSL_ENSURE( xIfc.is(), "Couldn't create a table" );
1193 
1194  if( xIfc.is() )
1195  xTable.set( xIfc, UNO_QUERY );
1196  }
1197 
1198  if( xTable.is() )
1199  {
1200  xTable->initialize( 1, 1 );
1201 
1202  try
1203  {
1204  m_xTextContent = xTable;
1205  GetImport().GetTextImport()->InsertTextContent( m_xTextContent );
1206  }
1207  catch( IllegalArgumentException& )
1208  {
1209  xTable = nullptr;
1210  }
1211  }
1212 
1213  if( xTable.is() )
1214  {
1215  //FIXME
1216  // xml:id for RDF metadata
1217  GetImport().SetXmlId(xTable, sXmlId);
1218 
1219  pXTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTable);
1220 
1221  Reference < XCellRange > xCellRange( xTable, UNO_QUERY );
1222  Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 );
1223  Reference < XText> xText( xCell, UNO_QUERY );
1224  m_xOldCursor = GetImport().GetTextImport()->GetCursor();
1225  GetImport().GetTextImport()->SetCursor( xText->createTextCursor() );
1226 
1227  // take care of open redlines for tables
1228  GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1229  }
1230  if( !pXTable )
1231  return;
1232 
1233  SwFrameFormat *const pTableFrameFormat = pXTable->GetFrameFormat();
1234  OSL_ENSURE( pTableFrameFormat, "table format missing" );
1235  SwTable *pTable = SwTable::FindTable( pTableFrameFormat );
1236  OSL_ENSURE( pTable, "table missing" );
1237  m_pTableNode = pTable->GetTableNode();
1238  OSL_ENSURE( m_pTableNode, "table node missing" );
1239 
1240  pTableFrameFormat->SetName( sTableName );
1241 
1242  SwTableLine *pLine1 = m_pTableNode->GetTable().GetTabLines()[0U];
1243  m_pBox1 = pLine1->GetTabBoxes()[0U];
1244  m_pSttNd1 = m_pBox1->GetSttNd();
1245 }
1246 
1248  SwXMLTableContext *pTable ) :
1249  XMLTextTableContext( rImport ),
1250  m_pRows( new SwXMLTableRows_Impl ),
1251  m_pTableNode( pTable->m_pTableNode ),
1252  m_pBox1( nullptr ),
1253  m_bOwnsBox1( false ),
1254  m_pSttNd1( nullptr ),
1255  m_pBoxFormat( nullptr ),
1256  m_pLineFormat( nullptr ),
1257  m_xParentTable( pTable ),
1258  m_bFirstSection( false ),
1259  m_bRelWidth( true ),
1260  m_bHasSubTables( false ),
1261  m_nHeaderRows( 0 ),
1262  m_nCurRow( 0 ),
1263  m_nCurCol( 0 ),
1264  m_nNonMergedCurCol( 0 ),
1265  m_nWidth( 0 )
1266 {
1267 }
1268 
1270 {
1271  if (m_bOwnsBox1)
1272  delete m_pBox1;
1274  m_pSharedBoxFormats.reset();
1275  m_pRows.reset();
1276 
1277  // close redlines on table end nodes
1278  GetImport().GetTextImport()->RedlineAdjustStartNodeCursor();
1279 }
1280 
1281 css::uno::Reference<css::xml::sax::XFastContextHandler> SwXMLTableContext::createFastChildContext(
1282  sal_Int32 nElement,
1283  const Reference< xml::sax::XFastAttributeList > & xAttrList )
1284 {
1285  bool bHeader = false;
1286  switch (nElement)
1287  {
1289  case XML_ELEMENT(LO_EXT, XML_TABLE_ROW):
1290  if( IsInsertRowPossible() )
1291  return new SwXMLTableRowContext_Impl( GetSwImport(), nElement, xAttrList, this );
1292  break;
1294  bHeader = true;
1295  [[fallthrough]];
1297  return new SwXMLTableRowsContext_Impl( GetSwImport(), this, bHeader );
1300  // There are slight differences between <table:table-columns> and
1301  // <table:table-columns-groups>. However, none of these are
1302  // supported in Writer (they are Calc-only features), so we
1303  // support column groups by simply using the <table:table-columns>
1304  // token for column groups, too.
1306  if( IsValid() )
1307  return new SwXMLTableColsContext_Impl( GetSwImport(), this );
1308  break;
1310  case XML_ELEMENT(LO_EXT, XML_TABLE_COLUMN):
1311  if( IsValid() && IsInsertColPossible() )
1312  return new SwXMLTableColContext_Impl( GetSwImport(), xAttrList,
1313  this );
1314  break;
1316  // save context for later processing (discard old context, if approp.)
1317  if( IsValid() )
1318  {
1320  return m_xDDESource;
1321  }
1322  break;
1323  }
1324  return nullptr;
1325 }
1326 
1327 void SwXMLTableContext::InsertColumn( sal_Int32 nWidth2, bool bRelWidth2,
1328  const OUString *pDfltCellStyleName )
1329 {
1330  OSL_ENSURE( m_nCurCol < USHRT_MAX,
1331  "SwXMLTableContext::InsertColumn: no space left" );
1332  if( m_nCurCol >= USHRT_MAX )
1333  return;
1334 
1335  if( nWidth2 < MINLAY )
1336  nWidth2 = MINLAY;
1337  else if( nWidth2 > MAX_WIDTH )
1338  nWidth2 = MAX_WIDTH;
1339  m_aColumnWidths.emplace_back(nWidth2, bRelWidth2 );
1340  if( !((pDfltCellStyleName && !pDfltCellStyleName->isEmpty()) ||
1342  return;
1343 
1345  {
1347  sal_uLong nCount = m_aColumnWidths.size() - 1;
1348  while( nCount-- )
1349  m_xColumnDefaultCellStyleNames->push_back(OUString());
1350  }
1351 
1352  if(pDfltCellStyleName)
1353  m_xColumnDefaultCellStyleNames->push_back(*pDfltCellStyleName);
1354  else
1355  m_xColumnDefaultCellStyleNames->push_back(OUString());
1356 }
1357 
1358 sal_Int32 SwXMLTableContext::GetColumnWidth( sal_uInt32 nCol,
1359  sal_uInt32 nColSpan ) const
1360 {
1361  sal_uInt32 nLast = nCol+nColSpan;
1362  if( nLast > m_aColumnWidths.size() )
1363  nLast = m_aColumnWidths.size();
1364 
1365  sal_Int32 nWidth2 = 0;
1366  for( sal_uInt32 i=nCol; i < nLast; ++i )
1367  nWidth2 += m_aColumnWidths[i].width;
1368 
1369  return nWidth2;
1370 }
1371 
1372 OUString SwXMLTableContext::GetColumnDefaultCellStyleName( sal_uInt32 nCol ) const
1373 {
1374  if( m_xColumnDefaultCellStyleNames && nCol < m_xColumnDefaultCellStyleNames->size())
1375  return (*m_xColumnDefaultCellStyleNames)[static_cast<size_t>(nCol)];
1376 
1377  return OUString();
1378 }
1379 
1380 void SwXMLTableContext::InsertCell( const OUString& rStyleName,
1381  sal_uInt32 nRowSpan, sal_uInt32 nColSpan,
1382  const SwStartNode *pStartNode,
1383  SwXMLTableContext *pTable,
1384  bool bProtect,
1385  const OUString* pFormula,
1386  bool bHasValue,
1387  double fValue,
1388  OUString const*const pStringValue )
1389 {
1390  OSL_ENSURE( m_nCurCol < GetColumnCount(),
1391  "SwXMLTableContext::InsertCell: row is full" );
1392  OSL_ENSURE( m_nCurRow < USHRT_MAX,
1393  "SwXMLTableContext::InsertCell: table is full" );
1394  if( m_nCurCol >= USHRT_MAX || m_nCurRow > USHRT_MAX )
1395  return;
1396 
1397  OSL_ENSURE( nRowSpan >=1, "SwXMLTableContext::InsertCell: row span is 0" );
1398  if( 0 == nRowSpan )
1399  nRowSpan = 1;
1400  OSL_ENSURE( nColSpan >=1, "SwXMLTableContext::InsertCell: col span is 0" );
1401  if( 0 == nColSpan )
1402  nColSpan = 1;
1403 
1404  // Until it is possible to add columns here, fix the column span.
1405  sal_uInt32 nColsReq = m_nCurCol + nColSpan;
1406  if( nColsReq > GetColumnCount() )
1407  {
1408  nColSpan = GetColumnCount() - m_nCurCol;
1409  nColsReq = GetColumnCount();
1410  }
1411 
1412  // Check whether there are cells from a previous line already that reach
1413  // into the current row.
1414  if( m_nCurRow > 0 && nColSpan > 1 )
1415  {
1416  SwXMLTableRow_Impl *pCurRow = (*m_pRows)[m_nCurRow].get();
1417  sal_uInt32 nLastCol = GetColumnCount() < nColsReq ? GetColumnCount()
1418  : nColsReq;
1419  for( sal_uInt32 i=m_nCurCol+1; i<nLastCol; ++i )
1420  {
1421  if( pCurRow->GetCell(i)->IsUsed() )
1422  {
1423  // If this cell is used, the column span is truncated
1424  nColSpan = i - m_nCurCol;
1425  nColsReq = i;
1426  break;
1427  }
1428  }
1429  }
1430 
1431  sal_uInt32 nRowsReq = m_nCurRow + nRowSpan;
1432  if( nRowsReq > USHRT_MAX )
1433  {
1434  nRowSpan = USHRT_MAX - m_nCurRow;
1435  nRowsReq = USHRT_MAX;
1436  }
1437 
1438  // Add columns (if # required columns greater than # columns):
1439  // This should never happen, since we require column definitions!
1440  if ( nColsReq > GetColumnCount() )
1441  {
1442  for( sal_uInt32 i=GetColumnCount(); i<nColsReq; ++i )
1443  {
1444  m_aColumnWidths.emplace_back(MINLAY, true );
1445  }
1446  // adjust columns in *all* rows, if columns must be inserted
1447  for (size_t i = 0; i < m_pRows->size(); ++i)
1448  (*m_pRows)[i]->Expand( nColsReq, i<m_nCurRow );
1449  }
1450 
1451  // Add rows
1452  if (m_pRows->size() < nRowsReq)
1453  {
1454  for (size_t i = m_pRows->size(); i < nRowsReq; ++i)
1455  m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1456  "", GetColumnCount()));
1457  }
1458 
1459  OUString sStyleName( rStyleName );
1460  if( sStyleName.isEmpty() )
1461  {
1462  sStyleName = (*m_pRows)[m_nCurRow]->GetDefaultCellStyleName();
1463  if( sStyleName.isEmpty() && m_xColumnDefaultCellStyleNames )
1464  {
1465  sStyleName = GetColumnDefaultCellStyleName( m_nCurCol );
1466  if( sStyleName.isEmpty() )
1467  sStyleName = m_aDfltCellStyleName;
1468  }
1469  }
1470 
1471  // Fill the cells
1472  for( sal_uInt32 i=nColSpan; i>0; --i )
1473  {
1474  for( sal_uInt32 j=nRowSpan; j>0; --j )
1475  {
1476  const bool bCovered = i != nColSpan || j != nRowSpan;
1477  SwXMLTableCell_Impl *pCell = GetCell( nRowsReq-j, nColsReq-i );
1478  if (!pCell)
1479  throw css::lang::IndexOutOfBoundsException();
1480  pCell->Set( sStyleName, j, i, pStartNode,
1481  pTable, bProtect, pFormula, bHasValue, bCovered, fValue,
1482  pStringValue );
1483  }
1484  }
1485 
1486  // Set current col to the next (free) column
1487  m_nCurCol = nColsReq;
1488  m_nNonMergedCurCol = nColsReq;
1489  while( m_nCurCol<GetColumnCount() && GetCell(m_nCurRow,m_nCurCol)->IsUsed() )
1490  m_nCurCol++;
1491 }
1492 
1493 void SwXMLTableContext::InsertCoveredCell(const OUString& rStyleName)
1494 {
1497  if (!pCell)
1498  {
1499  return;
1500  }
1501 
1502  pCell->SetStyleName(rStyleName);
1503 }
1504 
1505 void SwXMLTableContext::InsertRow( const OUString& rStyleName,
1506  const OUString& rDfltCellStyleName,
1507  bool bInHead )
1508 {
1509  OSL_ENSURE( m_nCurRow < USHRT_MAX,
1510  "SwXMLTableContext::InsertRow: no space left" );
1511  if( m_nCurRow >= USHRT_MAX )
1512  return;
1513 
1514  // Make sure there is at least one column.
1515  if( 0==m_nCurRow && 0 == GetColumnCount() )
1516  InsertColumn( USHRT_MAX, true );
1517 
1518  if (m_nCurRow < m_pRows->size())
1519  {
1520  // The current row has already been inserted because of a row span
1521  // of a previous row.
1522  (*m_pRows)[m_nCurRow]->Set(
1523  rStyleName, rDfltCellStyleName );
1524  }
1525  else
1526  {
1527  // add a new row
1528  m_pRows->push_back(std::make_unique<SwXMLTableRow_Impl>(
1529  rStyleName, GetColumnCount(),
1530  &rDfltCellStyleName));
1531  }
1532 
1533  // We start at the first column ...
1534  m_nCurCol=0;
1535  m_nNonMergedCurCol = 0;
1536 
1537  // ... but this cell may be occupied already.
1538  while( m_nCurCol<GetColumnCount() && GetCell(m_nCurRow,m_nCurCol)->IsUsed() )
1539  m_nCurCol++;
1540 
1541  if( bInHead && m_nHeaderRows == m_nCurRow )
1542  m_nHeaderRows++;
1543 }
1544 
1545 void SwXMLTableContext::InsertRepRows( sal_uInt32 nCount )
1546 {
1547  const SwXMLTableRow_Impl *pSrcRow = (*m_pRows)[m_nCurRow-1].get();
1548  while( nCount > 1 && IsInsertRowPossible() )
1549  {
1550  InsertRow( pSrcRow->GetStyleName(), pSrcRow->GetDefaultCellStyleName(),
1551  false );
1552  while( m_nCurCol < GetColumnCount() )
1553  {
1554  if( !GetCell(m_nCurRow,m_nCurCol)->IsUsed() )
1555  {
1556  const SwXMLTableCell_Impl *pSrcCell =
1557  GetCell( m_nCurRow-1, m_nCurCol );
1558  InsertCell( pSrcCell->GetStyleName(), 1U,
1559  pSrcCell->GetColSpan(),
1561  nullptr, pSrcCell->IsProtected(),
1562  &pSrcCell->GetFormula(),
1563  pSrcCell->HasValue(), pSrcCell->GetValue(),
1564  pSrcCell->GetStringValue() );
1565  }
1566  }
1567  FinishRow();
1568  nCount--;
1569  }
1570 }
1571 
1573 {
1574  // Insert an empty cell at the end of the line if the row is not complete
1575  if( m_nCurCol < GetColumnCount() )
1576  {
1577  InsertCell( "", 1U, GetColumnCount() - m_nCurCol,
1578  InsertTableSection() );
1579  }
1580 
1581  // Move to the next row.
1582  m_nCurRow++;
1583 }
1584 
1586  sal_uInt32 nCol ) const
1587 {
1588  const SwXMLTableCell_Impl *pPrevCell = nullptr;
1589  if( GetColumnCount() == nCol )
1590  {
1591  // The last cell is the right one here.
1592  pPrevCell = GetCell( m_pRows->size() - 1U, GetColumnCount() - 1 );
1593  }
1594  else if( nCol > 0 )
1595  {
1596  // The previous cell in this row.
1597  pPrevCell = GetCell( nRow, nCol-1 );
1598  }
1599  else if( nRow > 0 )
1600  {
1601  // The last cell from the previous row.
1602  pPrevCell = GetCell( nRow-1, GetColumnCount()-1 );
1603  }
1604 
1605  const SwStartNode *pSttNd = nullptr;
1606  if( pPrevCell )
1607  {
1608  if( pPrevCell->GetStartNode() )
1609  pSttNd = pPrevCell->GetStartNode();
1610  // #i95726# - Some fault tolerance
1611 // else
1612  else if ( pPrevCell->GetSubTable() )
1613  pSttNd = pPrevCell->GetSubTable()->GetLastStartNode();
1614 
1615  OSL_ENSURE( pSttNd != nullptr,
1616  "table corrupt" );
1617  }
1618 
1619  return pSttNd;
1620 }
1621 
1622 void SwXMLTableContext::FixRowSpan( sal_uInt32 nRow, sal_uInt32 nCol,
1623  sal_uInt32 nColSpan )
1624 {
1625  sal_uInt32 nLastCol = nCol + nColSpan;
1626  for( sal_uInt32 i = nCol; i < nLastCol; i++ )
1627  {
1628  sal_uInt32 j = nRow;
1629  sal_uInt32 nRowSpan = 1;
1630  SwXMLTableCell_Impl *pCell = GetCell( j, i );
1631  while( pCell && pCell->GetRowSpan() > 1 )
1632  {
1633  pCell->SetRowSpan( nRowSpan++ );
1634  pCell = j > 0 ? GetCell( --j, i ) : nullptr;
1635  }
1636  }
1637 }
1638 
1639 void SwXMLTableContext::ReplaceWithEmptyCell( sal_uInt32 nRow, sal_uInt32 nCol, bool bRows )
1640 {
1641  const SwStartNode *pPrevSttNd = GetPrevStartNode( nRow, nCol );
1642  const SwStartNode *pSttNd = InsertTableSection( pPrevSttNd );
1643 
1644  const SwXMLTableCell_Impl *pCell = GetCell( nRow, nCol );
1645  sal_uInt32 nLastRow = bRows ? nRow + pCell->GetRowSpan() : nRow + 1;
1646  sal_uInt32 nLastCol = nCol + pCell->GetColSpan();
1647 
1648  for( sal_uInt32 i=nRow; i<nLastRow; i++ )
1649  {
1650  SwXMLTableRow_Impl *pRow = (*m_pRows)[i].get();
1651  for( sal_uInt32 j=nCol; j<nLastCol; j++ )
1652  pRow->GetCell( j )->SetStartNode( pSttNd );
1653  }
1654 
1655 }
1656 
1658  SwTableLine *pUpper )
1659 {
1660  // The topmost table is the only table that maintains the two members
1661  // pBox1 and bFirstSection.
1662  if( m_xParentTable.is() )
1663  return static_cast<SwXMLTableContext *>(m_xParentTable.get())->NewTableBox( pStNd,
1664  pUpper );
1665 
1666  SwTableBox *pBox;
1667 
1668  if( m_pBox1 &&
1669  m_pBox1->GetSttNd() == pStNd )
1670  {
1671  // if the StartNode is equal to the StartNode of the initially
1672  // created box, we use this box
1673  pBox = m_pBox1;
1674  pBox->SetUpper( pUpper );
1675  m_pBox1 = nullptr;
1676  m_bOwnsBox1 = false;
1677  }
1678  else
1679  pBox = new SwTableBox( m_pBoxFormat, *pStNd, pUpper );
1680 
1681  return pBox;
1682 }
1683 
1685  SwTableBox* pBox,
1686  const OUString& rStyleName,
1687  sal_Int32 nColumnWidth,
1688  bool bProtected,
1689  bool bMayShare,
1690  bool& bNew,
1691  bool* pModifyLocked )
1692 {
1693  if ( m_pSharedBoxFormats == nullptr )
1695 
1696  SwTableBoxFormat* pBoxFormat2;
1697 
1698  TableBoxIndex aKey( rStyleName, nColumnWidth, bProtected );
1699  map_BoxFormat::iterator aIter = m_pSharedBoxFormats->find( aKey );
1700  if ( aIter == m_pSharedBoxFormats->end() )
1701  {
1702  // unknown format so far -> construct a new one
1703 
1704  // get the old format, and reset all attributes
1705  // (but preserve FillOrder)
1706  pBoxFormat2 = static_cast<SwTableBoxFormat*>(pBox->ClaimFrameFormat());
1707  SwFormatFillOrder aFillOrder( pBoxFormat2->GetFillOrder() );
1708  pBoxFormat2->ResetAllFormatAttr(); // #i73790# - method renamed
1709  pBoxFormat2->SetFormatAttr( aFillOrder );
1710  bNew = true; // it's a new format now
1711 
1712  // share this format, if allowed
1713  if ( bMayShare )
1714  (*m_pSharedBoxFormats)[ aKey ] = pBoxFormat2;
1715  }
1716  else
1717  {
1718  // set the shared format
1719  pBoxFormat2 = aIter->second;
1720  pBox->ChgFrameFormat( pBoxFormat2, /*bNeedToReregister*/false );
1721  bNew = false; // copied from an existing format
1722 
1723  // claim it, if we are not allowed to share
1724  if ( !bMayShare )
1725  pBoxFormat2 = static_cast<SwTableBoxFormat*>(pBox->ClaimFrameFormat());
1726  }
1727 
1728  // lock format (if so desired)
1729  if ( pModifyLocked != nullptr )
1730  {
1731  (*pModifyLocked) = pBoxFormat2->IsModifyLocked();
1732  pBoxFormat2->LockModify();
1733  }
1734 
1735  return pBoxFormat2;
1736 }
1737 
1739  sal_uInt32 nTopRow,
1740  sal_uInt32 nLeftCol,
1741  sal_uInt32 nBottomRow,
1742  sal_uInt32 nRightCol )
1743 {
1744  //FIXME: here would be a great place to handle XmlId for cell
1745  SwTableBox *pBox = new SwTableBox( m_pBoxFormat, 0, pUpper );
1746 
1747  sal_uInt32 nColSpan = nRightCol - nLeftCol;
1748  sal_Int32 nColWidth = GetColumnWidth( nLeftCol, nColSpan );
1749 
1750  // TODO: Share formats!
1751  SwFrameFormat *pFrameFormat = pBox->ClaimFrameFormat();
1752  SwFormatFillOrder aFillOrder( pFrameFormat->GetFillOrder() );
1753  pFrameFormat->ResetAllFormatAttr(); // #i73790# - method renamed
1754  pFrameFormat->SetFormatAttr( aFillOrder );
1755 
1756  pFrameFormat->SetFormatAttr( SwFormatFrameSize( SwFrameSize::Variable, nColWidth ) );
1757 
1758  SwTableLines& rLines = pBox->GetTabLines();
1759  bool bSplitted = false;
1760 
1761  while( !bSplitted )
1762  {
1763  sal_uInt32 nStartRow = nTopRow;
1764  sal_uInt32 i;
1765 
1766  for( i = nTopRow; i < nBottomRow; i++ )
1767  {
1768  // Could the table be split behind the current row?
1769  bool bSplit = true;
1770  SwXMLTableRow_Impl *pRow = (*m_pRows)[i].get();
1771  for( sal_uInt32 j=nLeftCol; j<nRightCol; j++ )
1772  {
1773  bSplit = ( 1 == pRow->GetCell(j)->GetRowSpan() );
1774  if( !bSplit )
1775  break;
1776  }
1777  if( bSplit && (nStartRow>nTopRow || i+1<nBottomRow) )
1778  {
1779  SwTableLine *pLine =
1780  MakeTableLine( pBox, nStartRow, nLeftCol, i+1,
1781  nRightCol );
1782 
1783  rLines.push_back( pLine );
1784 
1785  nStartRow = i+1;
1786  bSplitted = true;
1787  }
1788  }
1789  if( !bSplitted )
1790  {
1791  // No splitting was possible. That for, we have to force it.
1792  // Ruthless!
1793 
1794  nStartRow = nTopRow;
1795  while( nStartRow < nBottomRow )
1796  {
1797  sal_uInt32 nMaxRowSpan = 0;
1798  SwXMLTableRow_Impl *pStartRow = (*m_pRows)[nStartRow].get();
1799  const SwXMLTableCell_Impl *pCell;
1800  for( i=nLeftCol; i<nRightCol; i++ )
1801  {
1802  pCell = pStartRow->GetCell(i);
1803  if( pCell->GetRowSpan() > nMaxRowSpan )
1804  nMaxRowSpan = pCell->GetRowSpan();
1805  }
1806 
1807  nStartRow += nMaxRowSpan;
1808  if( nStartRow<nBottomRow )
1809  {
1810  SwXMLTableRow_Impl *pPrevRow = (*m_pRows)[nStartRow - 1U].get();
1811  i = nLeftCol;
1812  while( i < nRightCol )
1813  {
1814  if( pPrevRow->GetCell(i)->GetRowSpan() > 1 )
1815  {
1816  const SwXMLTableCell_Impl *pCell2 =
1817  GetCell( nStartRow, i );
1818  const sal_uInt32 nColSpan2 = pCell2->GetColSpan();
1819  FixRowSpan( nStartRow-1, i, nColSpan2 );
1820  ReplaceWithEmptyCell( nStartRow, i, true );
1821  i += nColSpan2;
1822  }
1823  else
1824  {
1825  i++;
1826  }
1827  }
1828  }
1829  }
1830  // and now start over again...
1831  }
1832  }
1833 
1834  return pBox;
1835 }
1836 
1838  SwTableLine *pUpper, const SwXMLTableCell_Impl *pCell,
1839  sal_uInt32 nLeftCol, sal_uInt32 nRightCol )
1840 {
1841  //FIXME: here would be a great place to handle XmlId for cell
1842  SwTableBox *pBox;
1843  sal_uInt32 nColSpan = nRightCol - nLeftCol;
1844  sal_Int32 nColWidth = GetColumnWidth( nLeftCol, nColSpan );
1845 
1846  if( pCell->GetStartNode() )
1847  {
1848  pBox = NewTableBox( pCell->GetStartNode(), pUpper );
1849  }
1850  else
1851  {
1852  // and it is a table: therefore we build a new box and
1853  // put the rows of the table into the rows of the box
1854  pBox = new SwTableBox( m_pBoxFormat, 0, pUpper );
1855  pCell->GetSubTable()->MakeTable( pBox, nColWidth );
1856  }
1857 
1858  // Share formats!
1859  const OUString sStyleName = pCell->GetStyleName();
1860  bool bModifyLocked;
1861  bool bNew;
1862  SwTableBoxFormat *pBoxFormat2 = GetSharedBoxFormat(
1863  pBox, sStyleName, nColWidth, pCell->IsProtected(),
1864  pCell->GetStartNode() && pCell->GetFormula().isEmpty() &&
1865  ! pCell->HasValue(),
1866  bNew, &bModifyLocked );
1867 
1868  // if a new format was created, then we need to set the style
1869  if ( bNew )
1870  {
1871  // set style
1872  const SfxItemSet *pAutoItemSet = nullptr;
1873  if( pCell->GetStartNode() && !sStyleName.isEmpty() &&
1875  XmlStyleFamily::TABLE_CELL, sStyleName, &pAutoItemSet ) )
1876  {
1877  if( pAutoItemSet )
1878  pBoxFormat2->SetFormatAttr( *pAutoItemSet );
1879  }
1880  }
1881 
1882  if( pCell->GetStartNode() )
1883  {
1884  if (pCell->HasStringValue())
1885  {
1886  SwNodeIndex const aNodeIndex(*(pCell->GetStartNode()), 1);
1887  SwTextNode *const pTextNode(aNodeIndex.GetNode().GetTextNode());
1888  SAL_WARN_IF(!pTextNode, "sw", "Should have a text node in cell?");
1889  if (pTextNode)
1890  {
1891  SAL_WARN_IF(!pTextNode->GetText().isEmpty(), "sw",
1892  "why text here?");
1893  pTextNode->InsertText(*pCell->GetStringValue(),
1894  SwIndex(pTextNode, 0));
1895  }
1896  }
1897 
1898  // try to rescue broken documents with a certain pattern
1899  // if: 1) the cell has a default number format (number 0)
1900  // 2) the call has no formula
1901  // 3) the value is 0.0
1902  // 4) the text doesn't look anything like 0.0
1903  // [read: length > 10, or length smaller 10 and no 0 in it]
1904  // then make it a text cell!
1905  bool bSuppressNumericContent = false;
1906  if( pCell->HasValue() && (pCell->GetValue() == 0.0) &&
1907  pCell->GetFormula().isEmpty() &&
1908  !sStyleName.isEmpty() )
1909  {
1910  // default num format?
1911  if( const SwTableBoxNumFormat* pNumFormat = pBoxFormat2->GetItemIfSet( RES_BOXATR_FORMAT, false ) )
1912  {
1913  if (pNumFormat && (pNumFormat->GetValue() % SV_COUNTRY_LANGUAGE_OFFSET) == 0)
1914  {
1915  // only one text node?
1916  SwNodeIndex aNodeIndex( *(pCell->GetStartNode()), 1 );
1917  if( ( aNodeIndex.GetNode().EndOfSectionIndex() -
1918  aNodeIndex.GetNode().StartOfSectionIndex() ) == SwNodeOffset(2) )
1919  {
1920  SwTextNode* pTextNode= aNodeIndex.GetNode().GetTextNode();
1921  if( pTextNode != nullptr )
1922  {
1923  // check text: does it look like some form of 0.0?
1924  const OUString& rText = pTextNode->GetText();
1925  if( ( rText.getLength() > 10 ) ||
1926  ( rText.indexOf( '0' ) == -1 ) )
1927  {
1928  bSuppressNumericContent = true;
1929  }
1930  }
1931  }
1932  else
1933  bSuppressNumericContent = true; // several nodes
1934  }
1935  }
1936  }
1937 
1938  if( bSuppressNumericContent )
1939  {
1940  // suppress numeric content? Then reset number format!
1941  pBoxFormat2->ResetFormatAttr( RES_BOXATR_FORMULA );
1942  pBoxFormat2->ResetFormatAttr( RES_BOXATR_FORMAT );
1943  pBoxFormat2->ResetFormatAttr( RES_BOXATR_VALUE );
1944  }
1945  else
1946  {
1947  // the normal case: set formula and value (if available)
1948 
1949  const OUString& rFormula = pCell->GetFormula();
1950  if (!rFormula.isEmpty())
1951  {
1952  // formula cell: insert formula if valid
1953  SwTableBoxFormula aFormulaItem( rFormula );
1954  pBoxFormat2->SetFormatAttr( aFormulaItem );
1955  }
1956  else if (!pCell->HasValue() && pCell->HasStringValue())
1957  {
1958  // Check for another inconsistency:
1959  // No value but a non-textual format, i.e. a number format
1960  // Solution: the number format will be removed,
1961  // the cell gets the default text format.
1962  if( const SwTableBoxNumFormat* pNumFormat = m_pBoxFormat->GetItemIfSet( RES_BOXATR_FORMAT, false ) )
1963  {
1964  const SwDoc* pDoc = m_pBoxFormat->GetDoc();
1965  const SvNumberFormatter* pNumberFormatter = pDoc ?
1966  pDoc->GetNumberFormatter() : nullptr;
1967  if( pNumFormat != nullptr && pNumberFormatter &&
1968  !pNumberFormatter->GetEntry( pNumFormat->GetValue() )->IsTextFormat() )
1970  }
1971  }
1972  // always insert value, even if default
1973  if( pCell->HasValue() )
1974  {
1975  SwTableBoxValue aValueItem( pCell->GetValue() );
1976  pBoxFormat2->SetFormatAttr( aValueItem );
1977  }
1978  }
1979 
1980  // update cell content depend on the default language
1981  pBox->ActualiseValueBox();
1982  }
1983 
1984  // table cell protection
1985  if( pCell->IsProtected() )
1986  {
1987  SvxProtectItem aProtectItem( RES_PROTECT );
1988  aProtectItem.SetContentProtect( true );
1989  pBoxFormat2->SetFormatAttr( aProtectItem );
1990  }
1991 
1992  // restore old modify-lock state
1993  if (! bModifyLocked)
1994  pBoxFormat2->UnlockModify();
1995 
1996  pBoxFormat2->SetFormatAttr( SwFormatFrameSize( SwFrameSize::Variable, nColWidth ) );
1997 
1998  return pBox;
1999 }
2000 
2002  sal_uInt32 nTopRow,
2003  sal_uInt32 nLeftCol,
2004  sal_uInt32 nBottomRow,
2005  sal_uInt32 nRightCol )
2006 {
2007  //FIXME: here would be a great place to handle XmlId for row
2008  SwTableLine *pLine;
2009  if( !pUpper && 0UL==nTopRow )
2010  {
2011  pLine = m_pTableNode->GetTable().GetTabLines()[0U];
2012  }
2013  else
2014  {
2015  pLine = new SwTableLine( m_pLineFormat, 0, pUpper );
2016  }
2017 
2018  // TODO: Share formats!
2019  SwFrameFormat *pFrameFormat = pLine->ClaimFrameFormat();
2020  SwFormatFillOrder aFillOrder( pFrameFormat->GetFillOrder() );
2021  pFrameFormat->ResetAllFormatAttr(); // #i73790# - method renamed
2022  pFrameFormat->SetFormatAttr( aFillOrder );
2023 
2024  const SfxItemSet *pAutoItemSet = nullptr;
2025  const OUString& rStyleName = (*m_pRows)[nTopRow]->GetStyleName();
2026  if( 1 == (nBottomRow - nTopRow) &&
2027  !rStyleName.isEmpty() &&
2029  XmlStyleFamily::TABLE_ROW, rStyleName, &pAutoItemSet ) )
2030  {
2031  if( pAutoItemSet )
2032  pFrameFormat->SetFormatAttr( *pAutoItemSet );
2033  }
2034 
2035  SwTableBoxes& rBoxes = pLine->GetTabBoxes();
2036 
2037  sal_uInt32 nStartCol = nLeftCol;
2038  while( nStartCol < nRightCol )
2039  {
2040  for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2041  (*m_pRows)[nRow]->SetSplitable( true );
2042 
2043  sal_uInt32 nCol = nStartCol;
2044  sal_uInt32 nSplitCol = nRightCol;
2045  bool bSplitted = false;
2046  while( !bSplitted )
2047  {
2048  OSL_ENSURE( nCol < nRightCol, "Ran too far" );
2049 
2050  // Can be split after current HTML table column?
2051  // If yes, can the created region still be split to
2052  // rows if the next column is added to it?
2053  bool bSplit = true;
2054  bool bHoriSplitMayContinue = false;
2055  bool bHoriSplitPossible = false;
2056 
2057  if ( m_bHasSubTables )
2058  {
2059  // Convert row spans if the table has subtables:
2060  for( sal_uInt32 nRow=nTopRow; nRow<nBottomRow; nRow++ )
2061  {
2062  SwXMLTableCell_Impl *pCell = GetCell(nRow,nCol);
2063  // Could the table fragment be split horizontally behind
2064  // the current line?
2065  bool bHoriSplit = (*m_pRows)[nRow]->IsSplitable() &&
2066  nRow+1 < nBottomRow &&
2067  1 == pCell->GetRowSpan();
2068  (*m_pRows)[nRow]->SetSplitable( bHoriSplit );
2069 
2070  // Could the table fragment be split vertically behind the
2071  // current column (uptp the current line?
2072  bSplit &= ( 1 == pCell->GetColSpan() );
2073  if( bSplit )
2074  {
2075  bHoriSplitPossible |= bHoriSplit;
2076 
2077  // Could the current table fragment be split
2078  // horizontally behind the next column, too?
2079  bHoriSplit &= (nCol+1 < nRightCol &&
2080  1 == GetCell(nRow,nCol+1)->GetRowSpan());
2081  bHoriSplitMayContinue |= bHoriSplit;
2082  }
2083  }
2084  }
2085  else
2086  {
2087  // No subtables: we use the new table model.
2088  SwXMLTableCell_Impl *pCell = GetCell(nTopRow,nCol);
2089 
2090  // #i95726# - some fault tolerance
2091  if ( pCell == nullptr )
2092  {
2093  OSL_FAIL( "table seems to be corrupt." );
2094  break;
2095  }
2096 
2097  // Could the table fragment be split vertically behind the
2098  // current column (uptp the current line?
2099  bSplit = 1 == pCell->GetColSpan();
2100  }
2101 
2102 #if OSL_DEBUG_LEVEL > 0
2103  if( nCol == nRightCol-1 )
2104  {
2105  OSL_ENSURE( bSplit, "Split-Flag wrong" );
2106  if ( m_bHasSubTables )
2107  {
2108  OSL_ENSURE( !bHoriSplitMayContinue,
2109  "HoriSplitMayContinue-Flag wrong" );
2110  SwXMLTableCell_Impl *pTmpCell = GetCell( nTopRow, nStartCol );
2111  OSL_ENSURE( pTmpCell->GetRowSpan() != (nBottomRow-nTopRow) ||
2112  !bHoriSplitPossible, "HoriSplitPossible-Flag wrong" );
2113  }
2114  }
2115 #endif
2116 
2117  OSL_ENSURE( !m_bHasSubTables || !bHoriSplitMayContinue || bHoriSplitPossible,
2118  "bHoriSplitMayContinue, but not bHoriSplitPossible" );
2119 
2120  if( bSplit )
2121  {
2122  SwTableBox* pBox = nullptr;
2123  SwXMLTableCell_Impl *pCell = GetCell( nTopRow, nStartCol );
2124  // #i95726# - some fault tolerance
2125  if( ( !m_bHasSubTables || ( pCell->GetRowSpan() == (nBottomRow-nTopRow) ) ) &&
2126  pCell->GetColSpan() == (nCol+1-nStartCol) &&
2127  ( pCell->GetStartNode() || pCell->GetSubTable() ) )
2128  {
2129  // insert new empty cell for covered cells:
2130  sal_Int32 nBoxRowSpan = 1;
2131  if ( !m_bHasSubTables )
2132  {
2133  nBoxRowSpan = pCell->GetRowSpan();
2134  if ( pCell->IsCovered() )
2135  {
2136  nBoxRowSpan = -1 * nBoxRowSpan;
2137  ReplaceWithEmptyCell( nTopRow, nStartCol, false );
2138  }
2139  }
2140 
2141  // The remaining box neither contains lines nor rows (i.e.
2142  // is a content box
2143  nSplitCol = nCol + 1;
2144 
2145  pBox = MakeTableBox( pLine, pCell, nStartCol, nSplitCol );
2146 
2147  if ( 1 != nBoxRowSpan )
2148  pBox->setRowSpan( nBoxRowSpan );
2149 
2150  bSplitted = true;
2151  }
2152  else if( m_bHasSubTables && bHoriSplitPossible && bHoriSplitMayContinue )
2153  {
2154  // The table fragment could be split behind the current
2155  // column, and the remaining fragment could be divided
2156  // into lines. Anyway, it could be that this applies to
2157  // the next column, too. That for, we check the next
2158  // column but remember the current one as a good place to
2159  // split.
2160  nSplitCol = nCol + 1;
2161  }
2162  else if ( m_bHasSubTables )
2163  {
2164  // If the table resulting table fragment could be divided
2165  // into lines if splitting behind the current column, but
2166  // this doesn't apply for thr next column, we split begind
2167  // the current column. This applies for the last column,
2168  // too.
2169  // If the resulting box cannot be split into rows,
2170  // the split at the last split position we remembered.
2171  if( bHoriSplitPossible || nSplitCol > nCol+1 )
2172  {
2173  OSL_ENSURE( !bHoriSplitMayContinue,
2174  "bHoriSplitMayContinue==true" );
2175  OSL_ENSURE( bHoriSplitPossible || nSplitCol == nRightCol,
2176  "bHoriSplitPossible flag should be set" );
2177 
2178  nSplitCol = nCol + 1;
2179  }
2180 
2181  pBox = MakeTableBox( pLine, nTopRow, nStartCol,
2182  nBottomRow, nSplitCol );
2183  bSplitted = true;
2184  }
2185 
2186  OSL_ENSURE( m_bHasSubTables || pBox, "Colspan trouble" );
2187 
2188  if( pBox )
2189  rBoxes.push_back( pBox );
2190  }
2191  nCol++;
2192  }
2193  nStartCol = nSplitCol;
2194  }
2195 
2196  return pLine;
2197 }
2198 
2200 {
2201  // fix column widths
2202  std::vector<ColumnWidthInfo>::iterator colIter;
2203  sal_uInt32 nCols = GetColumnCount();
2204 
2205  // If there are empty rows (because of some row span of previous rows)
2206  // the have to be deleted. The previous rows have to be truncated.
2207 
2208  if (m_pRows->size() > m_nCurRow)
2209  {
2210  SwXMLTableRow_Impl *pPrevRow = (*m_pRows)[m_nCurRow - 1U].get();
2211  const SwXMLTableCell_Impl *pCell;
2212  for( size_t i = 0; i < m_aColumnWidths.size(); ++i )
2213  {
2214  pCell = pPrevRow->GetCell(i);
2215  if( pCell->GetRowSpan() > 1 )
2216  {
2217  FixRowSpan( m_nCurRow-1, i, 1UL );
2218  }
2219  }
2220  for (size_t i = m_pRows->size() - 1; i >= m_nCurRow; --i)
2221  m_pRows->pop_back();
2222  }
2223 
2224  if (m_pRows->empty())
2225  {
2226  InsertCell( "", 1U, nCols, InsertTableSection() );
2227  }
2228 
2229  // TODO: Do we have to keep both values, the relative and the absolute
2230  // width?
2231  sal_Int32 nAbsWidth = 0;
2232  sal_Int32 nMinAbsColWidth = 0;
2233  sal_Int32 nRelWidth = 0;
2234  sal_Int32 nMinRelColWidth = 0;
2235  sal_uInt32 nRelCols = 0;
2236  for( const auto& rCol : m_aColumnWidths)
2237  {
2238  if( rCol.isRelative )
2239  {
2240  nRelWidth += rCol.width;
2241  if( 0 == nMinRelColWidth || rCol.width < nMinRelColWidth )
2242  nMinRelColWidth = rCol.width;
2243  nRelCols++;
2244  }
2245  else
2246  {
2247  nAbsWidth += rCol.width;
2248  if( 0 == nMinAbsColWidth || rCol.width < nMinAbsColWidth )
2249  nMinAbsColWidth = rCol.width;
2250  }
2251  }
2252  sal_uInt32 nAbsCols = nCols - nRelCols;
2253 
2254  if( m_bRelWidth )
2255  {
2256  // If there a columns that have an absolute width, we have to
2257  // calculate a relative one for them.
2258  if( nAbsCols > 0 )
2259  {
2260  // All column that have absolute widths get relative widths;
2261  // these widths relate to each over like the original absolute
2262  // widths. The smallest column gets a width that has the same
2263  // value as the smallest column that has a relative width
2264  // already.
2265  if( 0 == nMinRelColWidth )
2266  nMinRelColWidth = nMinAbsColWidth;
2267 
2268  for( auto& rCol : m_aColumnWidths)
2269  {
2270  if( !rCol.isRelative )
2271  {
2272  if (nMinAbsColWidth == 0)
2273  throw o3tl::divide_by_zero();
2274  sal_Int32 nVal;
2275  if (o3tl::checked_multiply<sal_Int32>(rCol.width, nMinRelColWidth, nVal))
2276  throw std::overflow_error("overflow in multiply");
2277  sal_Int32 nRelCol = nVal / nMinAbsColWidth;
2278  rCol.width = nRelCol;
2279  rCol.isRelative = true;
2280  nRelWidth += nRelCol;
2281  nAbsCols--;
2282  if (nAbsCols <= 0)
2283  break;
2284  }
2285  }
2286  }
2287 
2288  if( !m_nWidth )
2289  {
2290  // This happens only for percentage values for the table itself.
2291  // In this case, the columns get the correct width even if
2292  // the sum of the relative widths is smaller than the available
2293  // width in TWIP. Therefore, we can use the relative width.
2294  m_nWidth = std::min(nRelWidth, MAX_WIDTH);
2295  }
2296  if( nRelWidth != m_nWidth && nRelWidth && nCols )
2297  {
2298  double n = static_cast<double>(m_nWidth) / static_cast<double>(nRelWidth);
2299  nRelWidth = 0;
2300  for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end() - 1; ++colIter)
2301  {
2302  sal_Int32 nW = static_cast<sal_Int32>( colIter->width * n);
2303  colIter->width = o3tl::narrowing<sal_uInt16>(nW);
2304  nRelWidth += nW;
2305  }
2306  m_aColumnWidths.back().width = (m_nWidth-nRelWidth);
2307  }
2308  }
2309  else
2310  {
2311  // If there are columns that have relative widths, we have to
2312  // calculate an absolute widths for them.
2313  if( nRelCols > 0 )
2314  {
2315  // The absolute space that is available for all columns with a
2316  // relative width.
2317  sal_Int32 nAbsForRelWidth =
2318  m_nWidth > nAbsWidth ? m_nWidth - nAbsWidth : sal_Int32(0L);
2319 
2320  // The relative width that has to be distributed in addition to
2321  // equally widthed columns.
2322  sal_Int32 nExtraRel = nRelWidth - (nRelCols * nMinRelColWidth);
2323 
2324  // The absolute space that may be distributed in addition to
2325  // minimum widthed columns.
2326  sal_Int32 nMinAbs = nRelCols * MINLAY;
2327  sal_Int32 nExtraAbs =
2328  nAbsForRelWidth > nMinAbs ? nAbsForRelWidth - nMinAbs : sal_Int32(0L);
2329 
2330  bool bMin = false; // Do all columns get the minimum width?
2331  bool bMinExtra = false; // Do all columns get the minimum width plus
2332  // some extra space?
2333 
2334  if( nAbsForRelWidth <= nMinAbs )
2335  {
2336  // If there is not enough space left for all columns to
2337  // get the minimum width, they get the minimum width, anyway.
2338  nAbsForRelWidth = nMinAbs;
2339  bMin = true;
2340  }
2341  else if( nAbsForRelWidth <= (nRelWidth * MINLAY) /
2342  nMinRelColWidth )
2343  {
2344  // If there is enough space for all columns to get the
2345  // minimum width, but not to get a width that takes the
2346  // relative width into account, each column gets the minimum
2347  // width plus some extra space that is based on the additional
2348  // space that is available.
2349  bMinExtra = true;
2350  }
2351  // Otherwise, if there is enough space for every column, every
2352  // column gets this space.
2353 
2354  for( auto& rCol : m_aColumnWidths )
2355  {
2356  if( rCol.isRelative )
2357  {
2358  sal_Int32 nAbsCol;
2359  if( 1 == nRelCols )
2360  {
2361  // The last column that has a relative width gets
2362  // all absolute space that is left.
2363  nAbsCol = nAbsForRelWidth;
2364  }
2365  else
2366  {
2367  if( bMin )
2368  {
2369  nAbsCol = MINLAY;
2370  }
2371  else if( bMinExtra )
2372  {
2373  sal_Int32 nExtraRelCol = rCol.width - nMinRelColWidth;
2374  nAbsCol = MINLAY + (nExtraRelCol * nExtraAbs) /
2375  nExtraRel;
2376  }
2377  else
2378  {
2379  nAbsCol = ( rCol.width * nAbsForRelWidth) / nRelWidth;
2380  }
2381  }
2382  rCol.width = nAbsCol;
2383  rCol.isRelative = false;
2384  nAbsForRelWidth -= nAbsCol;
2385  nAbsWidth += nAbsCol;
2386  nRelCols--;
2387  if (nRelCols <= 0)
2388  break;
2389  }
2390  }
2391  }
2392 
2393  if( nCols && nAbsWidth )
2394  {
2395  if( nAbsWidth < m_nWidth )
2396  {
2397  // If the table's width is larger than the sum of the absolute
2398  // column widths, every column get some extra width.
2399  sal_Int32 nExtraAbs = m_nWidth - nAbsWidth;
2400  sal_Int32 nAbsLastCol = m_aColumnWidths.back().width + nExtraAbs;
2401  for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end()-1; ++colIter )
2402  {
2403  sal_Int32 nAbsCol = colIter->width;
2404  sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2405  nAbsWidth;
2406  nAbsCol += nExtraAbsCol;
2407  colIter->width = nAbsCol;
2408  nAbsLastCol -= nExtraAbsCol;
2409  }
2410  m_aColumnWidths.back().width = nAbsLastCol;
2411  }
2412  else if( nAbsWidth > m_nWidth )
2413  {
2414  // If the table's width is smaller than the sum of the absolute
2415  // column widths, every column needs to shrink.
2416  // Every column gets the minimum width plus some extra width.
2417  sal_Int32 nExtraAbs = m_nWidth - (nCols * MINLAY);
2418  sal_Int32 nAbsLastCol = MINLAY + nExtraAbs;
2419  for( colIter = m_aColumnWidths.begin(); colIter < m_aColumnWidths.end()-1; ++colIter )
2420  {
2421  sal_Int32 nAbsCol = colIter->width;
2422  sal_Int32 nExtraAbsCol = (nAbsCol * nExtraAbs) /
2423  nAbsWidth;
2424  nAbsCol = MINLAY + nExtraAbsCol;
2425  colIter->width = nAbsCol;
2426  nAbsLastCol -= nExtraAbsCol;
2427  }
2428  m_aColumnWidths.back().width = nAbsLastCol;
2429  }
2430  }
2431  }
2432 
2433  SwTableLines& rLines =
2434  pBox ? pBox->GetTabLines()
2436 
2437  sal_uInt32 nStartRow = 0;
2438  sal_uInt32 nRows = m_pRows->size();
2439  for(sal_uInt32 i=0; i<nRows; ++i )
2440  {
2441  // Could we split the table behind the current line?
2442  bool bSplit = true;
2443  if ( m_bHasSubTables )
2444  {
2445  SwXMLTableRow_Impl *pRow = (*m_pRows)[i].get();
2446  for( sal_uInt32 j=0; j<nCols; j++ )
2447  {
2448  bSplit = ( 1 == pRow->GetCell(j)->GetRowSpan() );
2449  if( !bSplit )
2450  break;
2451  }
2452  }
2453 
2454  if( bSplit )
2455  {
2456  SwTableLine *pLine =
2457  MakeTableLine( pBox, nStartRow, 0UL, i+1, nCols );
2458  if( pBox || nStartRow>0 )
2459  rLines.push_back( pLine );
2460  nStartRow = i+1;
2461  }
2462  }
2463 }
2464 
2466 {
2467  // this method will modify the document directly -> lock SolarMutex
2468  // This will call all other MakeTable*(..) methods, so
2469  // those don't need to be locked separately.
2470  SolarMutexGuard aGuard;
2471 
2472  // #i97274# handle invalid tables
2473  if (!m_pRows || m_pRows->empty() || !GetColumnCount())
2474  {
2475  OSL_FAIL("invalid table: no cells; deleting...");
2477  m_pTableNode = nullptr;
2478  m_pBox1 = nullptr;
2479  m_bOwnsBox1 = false;
2480  m_pSttNd1 = nullptr;
2481  return;
2482  }
2483 
2484  SwXMLImport& rSwImport = GetSwImport();
2485 
2486  SwFrameFormat *pFrameFormat = m_pTableNode->GetTable().GetFrameFormat();
2487 
2488  sal_Int16 eHoriOrient = text::HoriOrientation::FULL;
2489  bool bSetHoriOrient = false;
2490 
2491  sal_uInt8 nPercentWidth = 0U;
2492 
2493  OUString sStyleName;
2495  m_pTableNode->GetTable().SetTableStyleName( sStyleName );
2498 
2499  const SfxItemSet *pAutoItemSet = nullptr;
2500  if( !m_aStyleName.isEmpty() &&
2501  rSwImport.FindAutomaticStyle(
2502  XmlStyleFamily::TABLE_TABLE, m_aStyleName, &pAutoItemSet ) &&
2503  pAutoItemSet )
2504  {
2505  const SvxLRSpaceItem *pLRSpace =
2506  pAutoItemSet->GetItemIfSet( RES_LR_SPACE, false );
2507 
2508  if( const SwFormatHoriOrient* pItem = pAutoItemSet->GetItemIfSet( RES_HORI_ORIENT, false ) )
2509  {
2510  eHoriOrient = pItem->GetHoriOrient();
2511  switch( eHoriOrient )
2512  {
2513  case text::HoriOrientation::FULL:
2514  if( pLRSpace )
2515  {
2516  eHoriOrient = text::HoriOrientation::NONE;
2517  bSetHoriOrient = true;
2518  }
2519  break;
2520  case text::HoriOrientation::LEFT:
2521  if( pLRSpace )
2522  {
2523  eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH;
2524  bSetHoriOrient = true;
2525  }
2526  break;
2527  default:
2528  ;
2529  }
2530  }
2531  else
2532  {
2533  bSetHoriOrient = true;
2534  }
2535 
2536  const SwFormatFrameSize *pSize =
2537  pAutoItemSet->GetItemIfSet( RES_FRM_SIZE, false );
2538 
2539  switch( eHoriOrient )
2540  {
2541  case text::HoriOrientation::FULL:
2543  // For text::HoriOrientation::NONE we would prefer to use the sum
2544  // of the relative column widths as reference width.
2545  // Unfortunately this works only if this sum interpreted as
2546  // twip value is larger than the space that is available.
2547  // We don't know that space, so we have to use MAX_WIDTH, too.
2548  // Even if a size is specified, it will be ignored!
2549  m_nWidth = MAX_WIDTH;
2550  break;
2551  default:
2552  if( pSize )
2553  {
2554  if( pSize->GetWidthPercent() )
2555  {
2556  // The width will be set in MakeTable_
2557  nPercentWidth = pSize->GetWidthPercent();
2558  }
2559  else
2560  {
2561  m_nWidth = pSize->GetWidth();
2562  sal_Int32 const min = static_cast<sal_Int32>(
2563  std::min<sal_uInt32>(GetColumnCount() * MINLAY, MAX_WIDTH));
2564  if( m_nWidth < min )
2565  {
2566  m_nWidth = min;
2567  }
2568  else if( m_nWidth > MAX_WIDTH )
2569  {
2570  m_nWidth = MAX_WIDTH;
2571  }
2572  m_bRelWidth = false;
2573  }
2574  }
2575  else
2576  {
2577  eHoriOrient = text::HoriOrientation::LEFT_AND_WIDTH == eHoriOrient
2578  ? text::HoriOrientation::NONE : text::HoriOrientation::FULL;
2579  bSetHoriOrient = true;
2580  m_nWidth = MAX_WIDTH;
2581  }
2582  break;
2583  }
2584 
2585  pFrameFormat->SetFormatAttr( *pAutoItemSet );
2586  }
2587  else
2588  {
2589  bSetHoriOrient = true;
2590  m_nWidth = MAX_WIDTH;
2591  }
2592 
2593  SwTableLine *pLine1 = m_pTableNode->GetTable().GetTabLines()[0U];
2594  assert(m_pBox1 == pLine1->GetTabBoxes()[0] && !m_bOwnsBox1 && "Why is box 1 change?");
2596  pLine1->GetTabBoxes().erase( pLine1->GetTabBoxes().begin() );
2597  m_bOwnsBox1 = true;
2598 
2599  m_pLineFormat = static_cast<SwTableLineFormat*>(pLine1->GetFrameFormat());
2601 
2602  MakeTable_();
2603 
2604  if( bSetHoriOrient )
2605  pFrameFormat->SetFormatAttr( SwFormatHoriOrient( 0, eHoriOrient ) );
2606 
2607  // This must be after the call to MakeTable_, because nWidth might be
2608  // changed there.
2609  pFrameFormat->LockModify();
2611  aSize.SetWidthPercent( nPercentWidth );
2612  pFrameFormat->SetFormatAttr( aSize );
2613  pFrameFormat->UnlockModify();
2614 
2615  for (std::unique_ptr<SwXMLTableRow_Impl> & rRow : *m_pRows)
2616  rRow->Dispose();
2617 
2618  // now that table is complete, change into DDE table (if appropriate)
2619  if (m_xDDESource.is())
2620  {
2621  // change existing table into DDE table:
2622  // 1) Get DDE field type (get data from dde-source context),
2623  SwDDEFieldType* pFieldType = lcl_GetDDEFieldType( m_xDDESource.get(),
2624  m_pTableNode );
2625 
2626  // 2) release the DDE source context,
2627  m_xDDESource.set(nullptr);
2628 
2629  // 3) create new DDE table, and
2630  std::unique_ptr<SwDDETable> pDDETable( new SwDDETable( m_pTableNode->GetTable(),
2631  pFieldType, false ) );
2632 
2633  // 4) set new (DDE)table at node.
2634  m_pTableNode->SetNewTable(std::move(pDDETable), false);
2635  }
2636 
2637  // ??? this is always false: root frame is only created in SwViewShell::Init
2639  {
2641  SwNodeIndex aIdx( *m_pTableNode->EndOfSectionNode(), 1 );
2642  m_pTableNode->MakeOwnFrames(&aIdx);
2643  }
2644 }
2645 
2646 void SwXMLTableContext::MakeTable( SwTableBox *pBox, sal_Int32 nW )
2647 {
2648  //FIXME: here would be a great place to handle XmlId for subtable
2651  m_nWidth = nW;
2653 
2654  MakeTable_( pBox );
2655 
2656  for (std::unique_ptr<SwXMLTableRow_Impl> & rpRow : *m_pRows)
2657  {
2658  // i#113600, to break the cyclic reference to SwXMLTableContext object
2659  rpRow->Dispose();
2660  }
2661 }
2662 
2664  const SwStartNode *const pPrevSttNd,
2665  OUString const*const pStringValueStyleName)
2666 {
2667  // The topmost table is the only table that maintains the two members
2668  // pBox1 and bFirstSection.
2669  if( m_xParentTable.is() )
2670  return static_cast<SwXMLTableContext *>(m_xParentTable.get())
2671  ->InsertTableSection(pPrevSttNd, pStringValueStyleName);
2672 
2673  const SwStartNode *pStNd;
2674  Reference<XUnoTunnel> xCursorTunnel( GetImport().GetTextImport()->GetCursor(),
2675  UNO_QUERY);
2676  OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" );
2677  OTextCursorHelper *pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
2678  OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
2679 
2680  if( m_bFirstSection )
2681  {
2682  // The Cursor already is in the first section
2683  pStNd = pTextCursor->GetPaM()->GetNode().FindTableBoxStartNode();
2684  m_bFirstSection = false;
2685  GetImport().GetTextImport()->SetStyleAndAttrs( GetImport(),
2686  GetImport().GetTextImport()->GetCursor(), "Standard", true );
2687  }
2688  else
2689  {
2691  const SwEndNode *pEndNd = pPrevSttNd ? pPrevSttNd->EndOfSectionNode()
2693  // #i78921# - make code robust
2694  OSL_ENSURE( pDoc, "<SwXMLTableContext::InsertTableSection(..)> - no <pDoc> at <SwXTextCursor> instance - <SwXTextCurosr> doesn't seem to be registered at a <SwUnoCursor> instance." );
2695  if ( !pDoc )
2696  {
2697  pDoc = &const_cast<SwDoc&>(pEndNd->GetDoc());
2698  }
2699  SwNodeOffset nOffset(pPrevSttNd ? 1 : 0);
2700  SwNodeIndex aIdx( *pEndNd, nOffset );
2701  SwTextFormatColl *pColl =
2703  pStNd = pDoc->GetNodes().MakeTextSection( aIdx, SwTableBoxStartNode,
2704  pColl );
2705  // Consider the case that a table is defined without a row.
2706  if( !pPrevSttNd && m_pBox1 != nullptr )
2707 
2708  {
2709  m_pBox1->m_pStartNode = pStNd;
2710  SwContentNode *pCNd = pDoc->GetNodes()[ pStNd->GetIndex() + 1 ]
2711  ->GetContentNode();
2712  SwPosition aPos( *pCNd );
2713  aPos.nContent.Assign( pCNd, 0U );
2714 
2715  const uno::Reference< text::XTextRange > xTextRange =
2716  SwXTextRange::CreateXTextRange( *pDoc, aPos, nullptr );
2717  Reference < XText > xText = xTextRange->getText();
2718  Reference < XTextCursor > xTextCursor =
2719  xText->createTextCursorByRange( xTextRange );
2720  GetImport().GetTextImport()->SetCursor( xTextCursor );
2721  }
2722  }
2723 
2724  if (pStringValueStyleName)
2725  { // fdo#62147: apply style to paragraph on string-value cell
2726  GetImport().GetTextImport()->SetStyleAndAttrs( GetImport(),
2727  GetImport().GetTextImport()->GetCursor(), *pStringValueStyleName,
2728  true, false, -1, false); // parameters same as sCellParaStyleName
2729  }
2730 
2731  return pStNd;
2732 }
2733 
2735 {
2736  if( IsValid() && !m_xParentTable.is() )
2737  {
2738  MakeTable();
2739  GetImport().GetTextImport()->SetCursor( m_xOldCursor );
2740  }
2741 }
2742 
2743 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTableNode * m_pTableNode
Definition: xmltbli.hxx:70
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:692
Starts a section of nodes in the document model.
Definition: node.hxx:313
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
constexpr TypedWhichId< SvxProtectItem > RES_PROTECT(100)
tools::Long GetWidth() const
sal_uInt32 m_nRowSpan
Definition: xmltbli.cxx:94
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:687
void SetRowsToRepeat(sal_uInt16 nNumOfRows)
Definition: swtable.hxx:197
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Marks a position in the document model.
Definition: pam.hxx:36
std::unique_ptr< SwXMLTableRows_Impl > m_pRows
Definition: xmltbli.hxx:68
XML_DDE_ITEM
void Expand(sal_uInt32 nCells, bool bOneCell)
Definition: xmltbli.cxx:258
bool FindAutomaticStyle(XmlStyleFamily nFamily, const OUString &rName, const SfxItemSet **ppItemSet) const
Definition: xmlfmt.cxx:1041
SvXMLImportContextRef m_xSubTable
Definition: xmltbli.cxx:91
sal_uInt32 GetColumnCount() const
Definition: xmltbli.hxx:202
void DelFrames(SwRootFrame const *pLayout=nullptr)
Method deletes all views of document for the node.
Definition: ndtbl.cxx:2437
bool IsSplitable() const
Definition: xmltbli.cxx:221
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
const OUString & GetText() const
Definition: ndtxt.hxx:218
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1410
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
void InsertRow(const OUString &rStyleName, const OUString &rDfltCellStyleName, bool bInHead)
Definition: xmltbli.cxx:1505
SwNodeOffset StartOfSectionIndex() const
Definition: node.hxx:683
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
XML_TABLE_HEADER_COLUMNS
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
const SwStartNode * m_pSttNd1
Definition: xmltbli.hxx:73
sal_uInt32 GetRowSpan() const
Definition: xmltbli.cxx:128
const SwStartNode * InsertTableSection(const SwStartNode *pPrevSttNd=nullptr, OUString const *pStringValueStyleName=nullptr)
Definition: xmltbli.cxx:2663
void SetStartNode(const SwStartNode *pSttNd)
Definition: xmltbli.cxx:184
XML_DDE_APPLICATION
const OUString & GetStyleName() const
Definition: xmltbli.cxx:223
sal_uIntPtr sal_uLong
OUString GetUniqueTableName() const
Definition: ndtbl.cxx:3892
SwTableLine * MakeTableLine(SwTableBox *pUpper, sal_uInt32 nTopRow, sal_uInt32 nLeftCol, sal_uInt32 nBottomRow, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:2001
OUString GetColumnDefaultCellStyleName(sal_uInt32 nCol) const
Definition: xmltbli.cxx:1372
#define MINLAY
Definition: swtypes.hxx:62
const SwPosition * GetMark() const
Definition: pam.hxx:210
const sal_Unicode cTokenSeparator
SwTableBoxFormat * m_pBoxFormat
Definition: xmltbli.hxx:75
SvXMLImport & GetImport()
sal_Int32 toInt32(OUString const &rStr)
sal_Int64 n
SfxLinkUpdateMode GetType() const
Definition: ddefld.hxx:82
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
Definition: ndtbl.cxx:3944
bool IsProtected() const
Definition: xmltbli.cxx:136
XML_AUTOMATIC_UPDATE
Definition: doc.hxx:187
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1483
#define max(a, b)
void MakeTable(SwTableBox *pBox, sal_Int32 nWidth)
Definition: xmltbli.cxx:2646
void push_back(SwTableLine *pLine)
Definition: swtable.hxx:92
SwTableLine is one table row in the document model.
Definition: swtable.hxx:357
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwTableBox * NewTableBox(const SwStartNode *pStNd, SwTableLine *pUpper)
Definition: xmltbli.cxx:1657
OUString m_aDfltCellStyleName
Definition: xmltbli.hxx:53
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
const OUString & GetFormula() const
Definition: xmltbli.cxx:133
rtl::Reference< XMLTextImportHelper > const & GetTextImport()
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(152)
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
rtl::Reference< SwXMLDDETableContext_Impl > m_xDDESource
Definition: xmltbli.hxx:86
bool IsCovered() const
Definition: xmltbli.cxx:137
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:204
void SetStyleName(const OUString &rStyleName)
Definition: xmltbli.cxx:131
static void convertDouble(OUStringBuffer &rBuffer, double fNumber, bool bWriteUnits, sal_Int16 nSourceUnit, sal_Int16 nTargetUnit)
OUString const & GetCmd() const
Definition: ddefld.cxx:190
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Templatized version of GetItemState() to directly return the correct type.
Definition: format.hxx:111
const SwXMLTableCell_Impl * GetCell(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1105
void Set(const OUString &rStyleName, const OUString &rDfltCellStyleName)
Definition: xmltbli.cxx:277
OUString const * GetStringValue() const
Definition: xmltbli.cxx:139
constexpr TypedWhichId< SwFormatHoriOrient > RES_HORI_ORIENT(103)
SwIndex nContent
Definition: pam.hxx:39
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
check if target position is in fly anchored at source range
static bool IsFuzzing()
void SetTableModel(bool bNew)
Definition: swtable.hxx:187
bool HasValue() const
Definition: xmltbli.cxx:135
int nCount
XML_TABLE_ROWS
#define XMLOFF_WARN_UNKNOWN(area, rIter)
bool IsValid() const
Definition: xmltbli.hxx:167
SwXMLTableContext * GetParentTable() const
Definition: xmltbli.hxx:197
virtual void SetName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2560
OUString m_aDefaultCellStyleName
Definition: xmltbli.cxx:204
css::uno::Reference< css::text::XTextCursor > m_xOldCursor
Definition: xmltbli.hxx:65
const SwTable & GetTable() const
Definition: node.hxx:506
virtual void DeleteSection(SwNode *pNode)=0
Delete section containing the node.
static OUString getPrefixAndNameFromToken(sal_Int32 nToken)
void SetSplitable(bool bSet)
Definition: xmltbli.cxx:220
void InsertCoveredCell(const OUString &rStyleName)
Sets formatting of an already created covered cell.
Definition: xmltbli.cxx:1493
const SwFormatFillOrder & GetFillOrder(bool=true) const
Frame-attributes - implemented in frmatr.hxx.
Definition: fmtfordr.hxx:49
const SwStartNode * GetPrevStartNode(sal_uInt32 nRow, sal_uInt32 nCol) const
Definition: xmltbli.cxx:1585
const char * sName
void ActualiseValueBox()
Definition: swtable.cxx:2758
const IDocumentFieldsAccess & getIDocumentFieldsAccess() const
Provides access to the document fields administration interface.
Definition: node.cxx:2103
const SwStartNode * m_pStartNode
Definition: xmltbli.cxx:93
const SwStartNode * m_pStartNode
Definition: swtable.hxx:428
virtual sal_uInt16 ResetAllFormatAttr()
Takes all hints from Delta-Array,.
Definition: format.cxx:647
SwXMLTableContext * GetSubTable() const
Definition: xmltbli.cxx:190
XML_TABLE_COLUMNS
SwStartNode * MakeTextSection(const SwNodeIndex &rWhere, SwStartNodeType eSttNdTyp, SwTextFormatColl *pColl)
Definition: nodes.cxx:1896
sal_uInt32 m_nCurCol
Definition: xmltbli.hxx:94
SvXMLImportContextRef m_xParentTable
Definition: xmltbli.hxx:84
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
XML_PROTECTED
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:2106
XML_TABLE_ROW
void ReplaceWithEmptyCell(sal_uInt32 nRow, sal_uInt32 nCol, bool bRows)
Definition: xmltbli.cxx:1639
void InsertRepRows(sal_uInt32 nCount)
Definition: xmltbli.cxx:1545
css::uno::Reference< css::text::XTextContent > m_xTextContent
Definition: xmltbli.hxx:66
Style of a layout element.
Definition: frmfmt.hxx:59
#define SAL_MAX_INT32
SwXMLTableContext(SwXMLImport &rImport, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
if set, call pBox->LockModify() and return old lock status
int i
OUString & GetDDEApplication()
Definition: xmltbli.cxx:941
SwDoc & GetDoc()
Definition: node.hxx:213
const SwPosition * GetPoint() const
Definition: pam.hxx:208
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
SwIndex & Assign(SwIndexReg *, sal_Int32)
Definition: index.cxx:206
void InsertColumn(sal_Int32 nWidth, bool bRelWidth, const OUString *pDfltCellStyleName=nullptr)
Definition: xmltbli.cxx:1327
bool IsInsertRowPossible() const
Definition: xmltbli.hxx:166
SwTableBox * m_pBox1
Definition: xmltbli.hxx:71
bool HasStringValue() const
Definition: xmltbli.cxx:138
void MakeTable_(SwTableBox *pBox=nullptr)
Definition: xmltbli.cxx:2199
OUString & GetDDEItem()
Definition: xmltbli.cxx:942
SwNodeOffset GetIndex() const
Definition: node.hxx:292
sal_uInt32 m_nNonMergedCurCol
Same as m_nCurCol, but not incremented multiple times for table cells with row span.
Definition: xmltbli.hxx:96
Marks a character position inside a document model node.
Definition: index.hxx:33
void UnlockModify()
Definition: calbck.hxx:209
bool IsInsertColPossible() const
Definition: xmltbli.hxx:165
bool mbProtected
Definition: xmltbli.cxx:1079
OUString & GetConnectionName()
Definition: xmltbli.cxx:940
virtual ~SwXMLTableContext() override
Definition: xmltbli.cxx:1269
const OUString & GetStyleName() const
Definition: xmltbli.cxx:132
SwXMLImport & GetSwImport()
Definition: xmltbli.hxx:152
void LockModify()
Definition: calbck.hxx:208
sal_Int32 m_nWidth
Definition: xmltbli.hxx:97
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:380
SwXMLTableCell_Impl(sal_uInt32 nRSpan=1, sal_uInt32 nCSpan=1)
Definition: xmltbli.cxx:104
size
bool operator==(const TableBoxIndex &rArg) const
Definition: xmltbli.cxx:1088
void MakeOwnFrames(SwNodeIndex *pIdxBehind)
Creates the frms for the table node (i.e. the TabFrames).
Definition: ndtbl.cxx:2394
static void convertDuration(OUStringBuffer &rBuffer, const double fTime)
Marks a node in the document model.
Definition: ndindex.hxx:30
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:457
#define SV_COUNTRY_LANGUAGE_OFFSET
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
sal_uInt8 GetWidthPercent() const
Definition: fmtfsize.hxx:91
std::vector< std::unique_ptr< SwXMLTableCell_Impl > > m_Cells
Definition: xmltbli.cxx:205
std::unique_ptr< map_BoxFormat > m_pSharedBoxFormats
Definition: xmltbli.hxx:82
SwTableLines & GetTabLines()
Definition: swtable.hxx:201
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
Definition: xmltbli.cxx:2734
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:112
SwTableLines & GetTabLines()
Definition: swtable.hxx:450
static bool convertBool(bool &rBool, std::u16string_view rString)
void SetXmlId(css::uno::Reference< css::uno::XInterface > const &i_xIfc, OUString const &i_rXmlId)
SwTableBoxFormat * GetSharedBoxFormat(SwTableBox *pBox, const OUString &rStyleName, sal_Int32 nColumnWidth, bool bProtected, bool bMayShare, bool &bNew, bool *pModifyLocked)
sets the appropriate SwTableBoxFormat at pBox.
Definition: xmltbli.cxx:1684
sal_uInt16 m_nHeaderRows
Definition: xmltbli.hxx:92
sal_Int32 mnWidth
Definition: xmltbli.cxx:1078
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:448
bool IsUsed() const
Definition: xmltbli.cxx:125
bool IsModifyLocked() const
Definition: calbck.hxx:210
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void Set(const OUString &rStyleName, sal_uInt32 nRSpan, sal_uInt32 nCSpan, const SwStartNode *pStNd, SwXMLTableContext *pTable, bool bProtect, const OUString *pFormula, bool bHasValue, bool bCovered, double dVal, OUString const *const pStringValue)
Definition: xmltbli.cxx:151
double GetValue() const
Definition: xmltbli.cxx:134
OUString & GetDDETopic()
Definition: xmltbli.cxx:943
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:368
void FixRowSpan(sal_uInt32 nRow, sal_uInt32 nCol, sal_uInt32 nColSpan)
Definition: xmltbli.cxx:1622
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: format.cxx:619
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:105
XML_TABLE_HEADER_ROWS
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:471
XML_TABLE_COLUMN
sal_uInt32 m_nColSpan
Definition: xmltbli.cxx:95
void ChgFrameFormat(SwTableBoxFormat *pNewFormat, bool bNeedToReregister=true)
Definition: swtable.cxx:1939
const SwStartNode * GetLastStartNode() const
Definition: xmltbli.hxx:207
#define SAL_WARN_IF(condition, area, stream)
OUString m_aStyleName
Definition: xmltbli.cxx:203
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
unsigned char sal_uInt8
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
virtual SwFieldType * InsertFieldType(const SwFieldType &)=0
sal_Int32 GetColumnWidth(sal_uInt32 nCol, sal_uInt32 nColSpan) const
Definition: xmltbli.cxx:1358
std::vector< ColumnWidthInfo > m_aColumnWidths
Definition: xmltbli.hxx:62
static OUString lcl_GenerateFieldTypeName(const OUString &sPrefix, SwTableNode *pTableNode)
Definition: xmltbli.cxx:991
void SetWidthPercent(sal_uInt8 n)
Definition: fmtfsize.hxx:95
virtual void SAL_CALL endFastElement(sal_Int32 Element) override
void SetTableStyleName(const OUString &rName)
Set the new table style name for this table.
Definition: swtable.hxx:194
#define SAL_INFO(area, stream)
OUString aName
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
static constexpr sal_Int32 MAX_WIDTH
Definition: xmltbli.hxx:102
SwNodes & GetNodes()
Definition: doc.hxx:408
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(151)
sal_uInt32 GetColSpan() const
Definition: xmltbli.cxx:130
#define XML_ELEMENT(prefix, name)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const Reference< xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmltbli.cxx:954
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:418
std::vector< std::unique_ptr< SwXMLTableRow_Impl > > SwXMLTableRows_Impl
Definition: xmltbli.hxx:39
SwTableBox * MakeTableBox(SwTableLine *pUpper, const SwXMLTableCell_Impl *pStartNode, sal_uInt32 nLeftCol, sal_uInt32 nRightCol)
Definition: xmltbli.cxx:1837
QPRO_FUNC_TYPE nType
XML_DDE_TOPIC
sal_uInt32 m_nCurRow
Definition: xmltbli.hxx:93
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
static SwDDEFieldType * lcl_GetDDEFieldType(SwXMLDDETableContext_Impl *pContext, SwTableNode *pTableNode)
Definition: xmltbli.cxx:1013
TABLE
SwXMLTableRow_Impl(const OUString &rStyleName, sal_uInt32 nCells, const OUString *pDfltCellStyleName=nullptr)
Definition: xmltbli.cxx:229
SwFrameFormat * ClaimFrameFormat()
Definition: swtable.cxx:1903
std::unordered_map< TableBoxIndex, SwTableBoxFormat *, TableBoxIndexHasher > map_BoxFormat
Definition: xmltbli.hxx:81
bool m_bFirstSection
Definition: xmltbli.hxx:88
const SwStartNode * FindTableBoxStartNode() const
Definition: node.hxx:198
void SetUpper(SwTableLine *pNew)
Definition: swtable.hxx:455
OUString msName
Definition: xmltbli.cxx:1077
TableBoxIndex(const OUString &rName, sal_Int32 nWidth, bool bProtected)
Definition: xmltbli.cxx:1081
#define SAL_WARN(area, stream)
Reference< XSingleServiceFactory > xFactory
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
std::optional< std::vector< OUString > > m_xColumnDefaultCellStyleNames
Definition: xmltbli.hxx:63
void setRowSpan(sal_Int32 nNewRowSpan)
Definition: swtable.cxx:82
bool m_bHasSubTables
Definition: xmltbli.hxx:90
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
Definition: xmltbli.cxx:1281
void SetContentProtect(bool bNew)
Ends a section of nodes in the document model.
Definition: node.hxx:343
bool GetIsAutomaticUpdate() const
Definition: xmltbli.cxx:944
SwXMLTableCell_Impl * GetCell(sal_uInt32 nCol)
Definition: xmltbli.cxx:248
OUString m_aTemplateName
Definition: xmltbli.hxx:54
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1214
Frame is variable in Var-direction.
void SetNewTable(std::unique_ptr< SwTable >, bool bNewFrames=true)
Definition: ndtbl.cxx:2482
SwDoc * GetDocFromXMLImport(SvXMLImport const &)
Definition: xmlimp.cxx:1621
const SwStartNode * GetStartNode() const
Definition: xmltbli.cxx:143
SwTableLineFormat * m_pLineFormat
Definition: xmltbli.hxx:76
const OUString & GetDefaultCellStyleName() const
Definition: xmltbli.cxx:224
constexpr sal_uInt16 XML_NAMESPACE_OOOW
OUString m_aStyleName
Definition: xmltbli.cxx:84
void InsertCell(const OUString &rStyleName, sal_uInt32 nRowSpan, sal_uInt32 nColSpan, const SwStartNode *pStNd, SwXMLTableContext *pTable=nullptr, bool bIsProtected=false, const OUString *pFormula=nullptr, bool bHasValue=false, double fValue=0.0, OUString const *const pStringValue=nullptr)
Definition: xmltbli.cxx:1380
OUString m_StringValue
Definition: xmltbli.cxx:86
SwXMLDDETableContext_Impl(SwXMLImport &rImport)
Definition: xmltbli.cxx:948
XML_DDE_SOURCE
OUString m_sFormula
Definition: xmltbli.cxx:88
void SetRowSpan(sal_uInt32 nSet)
Definition: xmltbli.cxx:129
SfxLinkUpdateMode
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864
OUString toString(OptionInfo const *info)
XML_NAME
bool m_bDetectedRangeSegmentation false
SwTableNode * GetTableNode() const
Definition: swtable.cxx:2113
size_t operator()(const TableBoxIndex &rArg) const
Definition: xmltbli.cxx:1099
XML_TABLE_COLUMN_GROUP
SW_DLLPUBLIC SwFrameFormat * GetFrameFormat()
Definition: unotbl.cxx:2003