LibreOffice Module sw (master) 1
ddetbl.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 <doc.hxx>
24#include <contentindex.hxx>
25#include <ndtxt.hxx>
26#include <swtable.hxx>
27#include <swddetbl.hxx>
28#include <fmtfld.hxx>
29#include <ddefld.hxx>
30#include <ndindex.hxx>
31#include <fldupde.hxx>
32#include <swtblfmt.hxx>
33#include <fieldhint.hxx>
34#include <osl/diagnose.h>
35#include <pam.hxx>
36
39SwDDETable::SwDDETable( SwTable& rTable, SwDDEFieldType* pDDEType, bool bUpdate )
40 : SwTable(rTable), m_aDepends(*this), m_pDDEType(pDDEType)
41{
43 // copy the table data
45 rTable.GetTabSortBoxes().clear();
46
48 rTable.GetTabLines().begin(), rTable.GetTabLines().end() ); // move lines
49 rTable.GetTabLines().clear();
50
51 if( !m_aLines.empty() )
52 {
53 const SwNode& rNd = *GetTabSortBoxes()[0]->GetSttNd();
54 if( rNd.GetNodes().IsDocNodes() )
55 {
56 pDDEType->IncRefCnt();
57
58 // update box content only if update flag is set (false in import)
59 if (bUpdate)
61 }
62 }
63}
64
66{
67 SwDoc* pDoc = GetFrameFormat()->GetDoc();
68 if (!pDoc->IsInDtor() && !m_aLines.empty())
69 {
70 assert(m_pTableNode);
72 {
74 }
75 }
76
77 // If it is the last dependent of the "deleted field" than delete it finally
78 if( m_pDDEType->IsDeleted() && m_pDDEType->HasOnlyOneListener() )
79 {
81 delete m_pDDEType;
82 m_pDDEType = nullptr;
83 }
84}
85
86void SwDDETable::SwClientNotify(const SwModify& rModify, const SfxHint& rHint)
87{
88 if (rHint.GetId() == SfxHintId::SwLegacyModify)
89 {
90 SwTable::SwClientNotify(rModify, rHint);
91 }
92 else if (rHint.GetId() == SfxHintId::SwField)
93 {
94 auto pFieldHint = static_cast<const SwFieldHint*>(&rHint);
95 pFieldHint->m_pPaM->DeleteMark(); // TODO: this is really hackish
96 // replace DDETable by real table
97 NoDDETable();
98 }
99 else if(const auto pLinkAnchorHint = dynamic_cast<const sw::LinkAnchorSearchHint*>(&rHint))
100 {
101 if(pLinkAnchorHint->m_rpFoundNode)
102 return;
103 const auto pNd = GetTabSortBoxes()[0]->GetSttNd();
104 if( pNd && &pLinkAnchorHint->m_rNodes == &pNd->GetNodes() )
105 pLinkAnchorHint->m_rpFoundNode = pNd;
106 }
107 else if(const sw::InRangeSearchHint* pInRangeHint = dynamic_cast<const sw::InRangeSearchHint*>(&rHint))
108 {
109 if(pInRangeHint->m_rIsInRange)
110 return;
111 const SwTableNode* pTableNd = GetTabSortBoxes()[0]->GetSttNd()->FindTableNode();
112 if( pTableNd->GetNodes().IsDocNodes() &&
113 pInRangeHint->m_nSttNd < pTableNd->EndOfSectionIndex() &&
114 pInRangeHint->m_nEndNd > pTableNd->GetIndex() )
115 pInRangeHint->m_rIsInRange = true;
116 } else if (const auto pGatherDdeTablesHint = dynamic_cast<const sw::GatherDdeTablesHint*>(&rHint))
117 {
118 pGatherDdeTablesHint->m_rvTables.push_back(this);
119 }
120 else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
121 {
122 if(m_pDDEType == &rModify)
123 m_pDDEType = const_cast<SwDDEFieldType*>(static_cast<const SwDDEFieldType*>(pModifyChangedHint->m_pNew));
124 }
125}
126
128{
129 OSL_ENSURE( GetFrameFormat(), "No FrameFormat" );
130
131 // Is this the correct NodesArray? (because of UNDO)
132 if( m_aLines.empty() )
133 return;
134 OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
135 if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
136 return;
137
138
139 OUString aExpand = m_pDDEType->GetExpansion().replaceAll("\r", "");
140 sal_Int32 nExpandTokenPos = 0;
141
142 for( size_t n = 0; n < m_aLines.size(); ++n )
143 {
144 OUString aLine = aExpand.getToken( 0, '\n', nExpandTokenPos );
145 sal_Int32 nLineTokenPos = 0;
146 SwTableLine* pLine = m_aLines[ n ];
147 for( size_t i = 0; i < pLine->GetTabBoxes().size(); ++i )
148 {
149 SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
150 OSL_ENSURE( pBox->GetSttIdx(), "no content box" );
151 SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
152 SwTextNode* pTextNode = aNdIdx.GetNode().GetTextNode();
153 OSL_ENSURE( pTextNode, "No Node" );
154 SwContentIndex aCntIdx( pTextNode, 0 );
155 pTextNode->EraseText( aCntIdx );
156 pTextNode->InsertText( aLine.getToken( 0, '\t', nLineTokenPos ), aCntIdx );
157
158 SwTableBoxFormat* pBoxFormat = static_cast<SwTableBoxFormat*>(pBox->GetFrameFormat());
159 pBoxFormat->LockModify();
160 pBoxFormat->ResetFormatAttr( RES_BOXATR_VALUE );
161 pBoxFormat->UnlockModify();
162 }
163 }
164
166 SwDoc* pDoc = GetFrameFormat()->GetDoc();
168 pDoc->getIDocumentFieldsAccess().SetFieldsDirty( true, nullptr, SwNodeOffset(0) );
169}
170
172{
173 return m_pDDEType;
174}
175
177{
178 // search table node
179 OSL_ENSURE( GetFrameFormat(), "No FrameFormat" );
180 SwDoc* pDoc = GetFrameFormat()->GetDoc();
181
182 // Is this the correct NodesArray? (because of UNDO)
183 if( m_aLines.empty() )
184 return;
185 OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
186 SwNode* pNd = const_cast<SwNode*>(static_cast<SwNode const *>(GetTabSortBoxes()[0]->GetSttNd()));
187 if( !pNd->GetNodes().IsDocNodes() )
188 return;
189
190 SwTableNode* pTableNd = pNd->FindTableNode();
191 OSL_ENSURE( pTableNd, "Where is the table?");
192
193 std::unique_ptr<SwTable> pNewTable(new SwTable( *this ));
194
195 // copy the table data
196 pNewTable->GetTabSortBoxes().insert( GetTabSortBoxes() ); // move content boxes
198
199 pNewTable->GetTabLines().insert( pNewTable->GetTabLines().begin(),
200 GetTabLines().begin(), GetTabLines().end() ); // move lines
201 GetTabLines().clear();
202
205
206 pTableNd->SetNewTable( std::move(pNewTable) ); // replace table
207}
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool SetFieldsDirty(bool b, const SwNode *pChk, SwNodeOffset nLen)=0
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
Provides access to settings of a document.
virtual SwFieldUpdateFlags getFieldUpdateFlags(bool bGlobalSettings) const =0
Get the current field update mode.
SfxHintId GetId() const
Marks a character position inside a document model content node (SwContentNode)
bool IsDeleted() const
Definition: ddefld.hxx:85
void IncRefCnt()
Definition: ddefld.hxx:97
const OUString & GetExpansion() const
Definition: ddefld.hxx:69
void DecRefCnt()
Definition: ddefld.hxx:98
sw::WriterMultiListener m_aDepends
Definition: swddetbl.hxx:28
SwDDEFieldType * GetDDEFieldType()
Definition: ddetbl.cxx:171
SwDDEFieldType * m_pDDEType
Definition: swddetbl.hxx:29
void ChangeContent()
Definition: ddetbl.cxx:127
void NoDDETable()
Definition: ddetbl.cxx:176
SwDDETable(SwTable &rTable, SwDDEFieldType *pDDEType, bool bUpdate=true)
Ctor moves all lines/boxes from a SwTable into itself.
Definition: ddetbl.cxx:39
virtual ~SwDDETable() override
Definition: ddetbl.cxx:65
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: ddetbl.cxx:86
Definition: doc.hxx:197
bool IsInDtor() const
Definition: doc.hxx:417
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
SwPaM * m_pPaM
Definition: fieldhint.hxx:31
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
virtual bool ResetFormatAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
Definition: format.cxx:618
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document settings interface.
Definition: format.cxx:711
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:691
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2555
void DeleteMark()
Definition: pam.hxx:232
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
SwNodeOffset GetSttIdx() const
Definition: swtable.cxx:2242
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:481
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:495
SwTableLine is one table row in the document model.
Definition: swtable.hxx:376
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:386
size_type size() const
Definition: swtable.hxx:76
iterator end()
Definition: swtable.hxx:79
void clear()
Definition: swtable.hxx:83
iterator insert(iterator aIt, SwTableLine *pLine)
Definition: swtable.hxx:86
iterator begin()
Definition: swtable.hxx:77
bool empty() const
Definition: swtable.hxx:75
void SetNewTable(std::unique_ptr< SwTable >, bool bNewFrames=true)
Definition: ndtbl.cxx:2507
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
SwTableSortBoxes m_TabSortContentBoxes
Definition: swtable.hxx:117
SwTableNode * m_pTableNode
Definition: swtable.hxx:126
SwTableLines & GetTabLines()
Definition: swtable.hxx:206
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:209
SwTableLines m_aLines
Definition: swtable.hxx:116
SwTable()
Definition: swtable.cxx:187
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: swtable.cxx:325
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:267
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
void EraseText(const SwContentIndex &rIdx, const sal_Int32 nCount=SAL_MAX_INT32, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
delete text content ATTENTION: must not be called with a range that overlaps the start of an attribut...
Definition: ndtxt.cxx:2777
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2372
std::pair< const_iterator, bool > insert(Value &&x)
void StartListening(SwModify *pDepend)
Definition: calbck.cxx:269
@ AUTOUPD_FIELD_AND_CHARTS
Definition: fldupde.hxx:26
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(158)
sal_Int64 n
size
int i
enumrange< T >::Iterator begin(enumrange< T >)
end
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16