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
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 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
91 switch(pLegacy->GetWhich())
92 {
95 break;
96 default:
97 SwTable::SwClientNotify(rModify, rHint);
98 }
99 }
100 else if (rHint.GetId() == SfxHintId::SwField)
101 {
102 auto pFieldHint = static_cast<const SwFieldHint*>(&rHint);
103 pFieldHint->m_pPaM->DeleteMark(); // TODO: this is really hackish
104 // replace DDETable by real table
105 NoDDETable();
106 }
107 else if(const auto pLinkAnchorHint = dynamic_cast<const sw::LinkAnchorSearchHint*>(&rHint))
108 {
109 if(pLinkAnchorHint->m_rpFoundNode)
110 return;
111 const auto pNd = GetTabSortBoxes()[0]->GetSttNd();
112 if( pNd && &pLinkAnchorHint->m_rNodes == &pNd->GetNodes() )
113 pLinkAnchorHint->m_rpFoundNode = pNd;
114 }
115 else if(const sw::InRangeSearchHint* pInRangeHint = dynamic_cast<const sw::InRangeSearchHint*>(&rHint))
116 {
117 if(pInRangeHint->m_rIsInRange)
118 return;
119 const SwTableNode* pTableNd = GetTabSortBoxes()[0]->GetSttNd()->FindTableNode();
120 if( pTableNd->GetNodes().IsDocNodes() &&
121 pInRangeHint->m_nSttNd < pTableNd->EndOfSectionIndex() &&
122 pInRangeHint->m_nEndNd > pTableNd->GetIndex() )
123 pInRangeHint->m_rIsInRange = true;
124 } else if (const auto pGatherDdeTablesHint = dynamic_cast<const sw::GatherDdeTablesHint*>(&rHint))
125 {
126 pGatherDdeTablesHint->m_rvTables.push_back(this);
127 }
128 else if (auto pModifyChangedHint = dynamic_cast<const sw::ModifyChangedHint*>(&rHint))
129 {
130 if(m_pDDEType == &rModify)
131 m_pDDEType = const_cast<SwDDEFieldType*>(static_cast<const SwDDEFieldType*>(pModifyChangedHint->m_pNew));
132 }
133}
134
136{
137 OSL_ENSURE( GetFrameFormat(), "No FrameFormat" );
138
139 // Is this the correct NodesArray? (because of UNDO)
140 if( m_aLines.empty() )
141 return;
142 OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
143 if( !GetTabSortBoxes()[0]->GetSttNd()->GetNodes().IsDocNodes() )
144 return;
145
146
147 OUString aExpand = m_pDDEType->GetExpansion().replaceAll("\r", "");
148 sal_Int32 nExpandTokenPos = 0;
149
150 for( size_t n = 0; n < m_aLines.size(); ++n )
151 {
152 OUString aLine = aExpand.getToken( 0, '\n', nExpandTokenPos );
153 sal_Int32 nLineTokenPos = 0;
154 SwTableLine* pLine = m_aLines[ n ];
155 for( size_t i = 0; i < pLine->GetTabBoxes().size(); ++i )
156 {
157 SwTableBox* pBox = pLine->GetTabBoxes()[ i ];
158 OSL_ENSURE( pBox->GetSttIdx(), "no content box" );
159 SwNodeIndex aNdIdx( *pBox->GetSttNd(), 1 );
160 SwTextNode* pTextNode = aNdIdx.GetNode().GetTextNode();
161 OSL_ENSURE( pTextNode, "No Node" );
162 SwContentIndex aCntIdx( pTextNode, 0 );
163 pTextNode->EraseText( aCntIdx );
164 pTextNode->InsertText( aLine.getToken( 0, '\t', nLineTokenPos ), aCntIdx );
165
166 SwTableBoxFormat* pBoxFormat = static_cast<SwTableBoxFormat*>(pBox->GetFrameFormat());
167 pBoxFormat->LockModify();
168 pBoxFormat->ResetFormatAttr( RES_BOXATR_VALUE );
169 pBoxFormat->UnlockModify();
170 }
171 }
172
174 SwDoc* pDoc = GetFrameFormat()->GetDoc();
176 pDoc->getIDocumentFieldsAccess().SetFieldsDirty( true, nullptr, SwNodeOffset(0) );
177}
178
180{
181 return m_pDDEType;
182}
183
185{
186 // search table node
187 OSL_ENSURE( GetFrameFormat(), "No FrameFormat" );
188 SwDoc* pDoc = GetFrameFormat()->GetDoc();
189
190 // Is this the correct NodesArray? (because of UNDO)
191 if( m_aLines.empty() )
192 return;
193 OSL_ENSURE( !GetTabSortBoxes().empty(), "Table without content?" );
194 SwNode* pNd = const_cast<SwNode*>(static_cast<SwNode const *>(GetTabSortBoxes()[0]->GetSttNd()));
195 if( !pNd->GetNodes().IsDocNodes() )
196 return;
197
198 SwTableNode* pTableNd = pNd->FindTableNode();
199 OSL_ENSURE( pTableNd, "Where is the table?");
200
201 std::unique_ptr<SwTable> pNewTable(new SwTable( *this ));
202
203 // copy the table data
204 pNewTable->GetTabSortBoxes().insert( GetTabSortBoxes() ); // move content boxes
206
207 pNewTable->GetTabLines().insert( pNewTable->GetTabLines().begin(),
208 GetTabLines().begin(), GetTabLines().end() ); // move lines
209 GetTabLines().clear();
210
213
214 pTableNd->SetNewTable( std::move(pNewTable) ); // replace table
215}
216
217/* 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:179
SwDDEFieldType * m_pDDEType
Definition: swddetbl.hxx:29
void ChangeContent()
Definition: ddetbl.cxx:135
void NoDDETable()
Definition: ddetbl.cxx:184
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:192
bool IsInDtor() const
Definition: doc.hxx:408
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:358
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:406
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:620
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document settings interface.
Definition: format.cxx:713
void LockModify()
Definition: calbck.hxx:208
void UnlockModify()
Definition: calbck.hxx:209
bool HasOnlyOneListener() const
Definition: calbck.hxx:203
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:136
Base class of the Writer document model elements.
Definition: node.hxx:84
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:876
SwNodeOffset GetIndex() const
Definition: node.hxx:296
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:721
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:370
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:705
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc....
Definition: nodes.cxx:2531
void DeleteMark()
Definition: pam.hxx:231
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:419
SwNodeOffset GetSttIdx() const
Definition: swtable.cxx:2049
SwFrameFormat * GetFrameFormat()
Definition: swtable.hxx:457
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:471
SwTableLine is one table row in the document model.
Definition: swtable.hxx:358
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:368
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:2473
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:201
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:204
SwTableLines m_aLines
Definition: swtable.hxx:116
SwTable()
Definition: swtable.cxx:183
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: swtable.cxx:321
SwTableSortBoxes & GetTabSortBoxes()
Definition: swtable.hxx:262
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:86
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:2724
OUString InsertText(const OUString &rStr, const SwContentIndex &rIdx, const SwInsertFlags nMode=SwInsertFlags::DEFAULT)
insert text content
Definition: ndtxt.cxx:2322
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(152)
constexpr TypedWhichId< SwMsgPoolItem > RES_UPDATEDDETBL(171)
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