LibreOffice Module sw (master)  1
docchart.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 <float.h>
21 #include <hintids.hxx>
22 #include <doc.hxx>
24 #include <IDocumentState.hxx>
26 #include <docary.hxx>
27 #include <ndindex.hxx>
28 #include <swtable.hxx>
29 #include <ndtxt.hxx>
30 #include <calc.hxx>
31 #include <cellfml.hxx>
32 #include <viewsh.hxx>
33 #include <ndole.hxx>
34 #include <calbck.hxx>
35 #include <cntfrm.hxx>
36 #include <swtblfmt.hxx>
37 #include <tblsel.hxx>
38 #include <cellatr.hxx>
39 
40 #include <unochart.hxx>
41 
43 {
44  GetFrameFormat()->GetDoc()->UpdateCharts( GetFrameFormat()->GetName() );
45 }
46 
47 bool SwTable::IsTableComplexForChart( const OUString& rSelection ) const
48 {
49  const SwTableBox* pSttBox, *pEndBox;
50  if( 2 < rSelection.getLength() )
51  {
52  const sal_Int32 nSeparator {rSelection.indexOf( ':' )};
53  OSL_ENSURE( -1 != nSeparator, "no valid selection" );
54 
55  // Remove brackets at the beginning and from the end
56  const sal_Int32 nOffset {'<' == rSelection[0] ? 1 : 0};
57  const sal_Int32 nLength {'>' == rSelection[ rSelection.getLength()-1 ]
58  ? rSelection.getLength()-1 : rSelection.getLength()};
59 
60  pSttBox = GetTableBox(rSelection.copy( nOffset, nSeparator - nOffset ));
61  pEndBox = GetTableBox(rSelection.copy( nSeparator+1, nLength - (nSeparator+1) ));
62  }
63  else
64  {
65  const SwTableLines* pLns = &GetTabLines();
66  pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
67  while( !pSttBox->GetSttNd() )
68  // Until the Content Box!
69  pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
70 
71  const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
72  pEndBox = pBoxes->back();
73  while( !pEndBox->GetSttNd() )
74  {
75  // Until the Content Box!
76  pLns = &pEndBox->GetTabLines();
77  pBoxes = &pLns->back()->GetTabBoxes();
78  pEndBox = pBoxes->back();
79  }
80  }
81 
82  return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
83  *pEndBox->GetSttNd() );
84 }
85 
87 {
89  if( pVSh )
90  {
91  const SwFrameFormats& rTableFormats = *GetTableFrameFormats();
92  for( size_t n = 0; n < rTableFormats.size(); ++n )
93  {
94  SwTable* pTmpTable;
95  const SwTableNode* pTableNd;
96  const SwFrameFormat* pFormat = rTableFormats[ n ];
97 
98  if( nullptr != ( pTmpTable = SwTable::FindTable( pFormat ) ) &&
99  nullptr != ( pTableNd = pTmpTable->GetTableNode() ) &&
100  pTableNd->GetNodes().IsDocNodes() )
101  {
102  UpdateCharts_( *pTmpTable, *pVSh );
103  }
104  }
105  }
106 }
107 
108 void SwDoc::UpdateCharts_( const SwTable& rTable, SwViewShell const & rVSh ) const
109 {
110  OUString aName( rTable.GetFrameFormat()->GetName() );
111  SwStartNode *pStNd;
112  SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
113  while( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
114  {
115  ++aIdx;
116  SwOLENode *pONd;
117  if( nullptr != ( pONd = aIdx.GetNode().GetOLENode() ) &&
118  aName == pONd->GetChartTableName() &&
119  pONd->getLayoutFrame( rVSh.GetLayout() ) )
120  {
122  if (pPCD)
123  pPCD->InvalidateTable( &rTable );
124  // following this the framework will now take care of repainting
125  // the chart or it's replacement image...
126  }
127  aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
128  }
129 }
130 
131 void SwDoc::UpdateCharts( const OUString &rName ) const
132 {
133  SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) );
134  if( pTmpTable )
135  {
137 
138  if( pVSh )
139  UpdateCharts_( *pTmpTable, *pVSh );
140  }
141 }
142 
143 void SwDoc::SetTableName( SwFrameFormat& rTableFormat, const OUString &rNewName )
144 {
145  const OUString aOldName( rTableFormat.GetName() );
146 
147  bool bNameFound = rNewName.isEmpty();
148  if( !bNameFound )
149  {
150  const SwFrameFormats& rTable = *GetTableFrameFormats();
151  for( size_t i = rTable.size(); i; )
152  {
153  const SwFrameFormat* pFormat;
154  if( !( pFormat = rTable[ --i ] )->IsDefault() &&
155  pFormat->GetName() == rNewName && IsUsed( *pFormat ) )
156  {
157  bNameFound = true;
158  break;
159  }
160  }
161  }
162 
163  if( !bNameFound )
164  rTableFormat.SetName( rNewName, true );
165  else
166  rTableFormat.SetName( GetUniqueTableName(), true );
167 
168  SwStartNode *pStNd;
169  SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
170  while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
171  {
172  ++aIdx;
173  SwOLENode *pNd = aIdx.GetNode().GetOLENode();
174  if( pNd && aOldName == pNd->GetChartTableName() )
175  {
176  pNd->SetChartTableName( rNewName );
177 
178  SwTable* pTable = SwTable::FindTable( &rTableFormat );
180  if (pPCD)
181  pPCD->InvalidateTable( pTable );
182  // following this the framework will now take care of repainting
183  // the chart or it's replacement image...
184  }
185  aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
186  }
188 }
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
Starts a section of nodes in the document model.
Definition: node.hxx:303
const SwTableBox * GetTableBox(const OUString &rName, const bool bPerformValidCheck=false) const
Definition: swtable.cxx:1344
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:161
void UpdateCharts() const
Definition: docchart.cxx:42
const SwFrameFormats * GetTableFrameFormats() const
Definition: doc.hxx:807
virtual void SetModified()=0
Must be called manually at changes of format.
OUString GetUniqueTableName() const
Definition: ndtbl.cxx:3852
const OUString & GetChartTableName() const
Definition: ndole.hxx:152
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1148
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
Definition: ndtbl.cxx:3904
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:422
void UpdateCharts_(const SwTable &rTable, SwViewShell const &rVSh) const
Definition: docchart.cxx:108
bool IsTableComplexForChart(const OUString &rSel) const
Definition: docchart.cxx:47
SwNode & GetNode() const
Definition: ndindex.hxx:118
void InvalidateTable(const SwTable *pTable)
Definition: unochart.cxx:1435
SwTableLine * front() const
Definition: swtable.hxx:79
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
SwTableLine * back() const
Definition: swtable.hxx:80
const OUString & GetName() const
Definition: format.hxx:111
virtual void SetName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2464
void UpdateCharts(const OUString &rName) const
Definition: docchart.cxx:131
Specific frame formats (frames, DrawObjects).
Definition: docary.hxx:201
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:1920
Style of a layout element.
Definition: frmfmt.hxx:57
virtual SwChartDataProvider * GetChartDataProvider(bool bCreate=false) const =0
returns or creates the data-provider for chart
int i
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:426
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:119
SwStartNode * GetStartNode()
Definition: node.hxx:591
IDocumentChartDataProviderAccess const & getIDocumentChartDataProviderAccess() const
Definition: doc.cxx:259
SwTableLines & GetTabLines()
Definition: swtable.hxx:198
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
SwTableLines & GetTabLines()
Definition: swtable.hxx:418
void SetChartTableName(const OUString &rNm)
Definition: ndole.hxx:153
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:354
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:103
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:439
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
bool IsUsed(const SwModify &) const
Definition: poolfmt.cxx:122
SwNodes & GetNodes()
Definition: doc.hxx:402
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
void DoUpdateAllCharts()
Definition: docchart.cxx:86
void SetTableName(SwFrameFormat &rTableFormat, const OUString &rNewName)
Definition: docchart.cxx:143
OString const aName
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2336
size_t size() const
Definition: docary.hxx:225
sal_Int32 const nLength
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2071
SwNodeIndex & Assign(SwNodes const &rNds, sal_uLong)
Definition: ndindex.hxx:271
SwTableNode * GetTableNode() const
Definition: swtable.cxx:1927