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 <doc.hxx>
22 #include <IDocumentState.hxx>
24 #include <docary.hxx>
25 #include <ndindex.hxx>
26 #include <swtable.hxx>
27 #include <viewsh.hxx>
28 #include <ndole.hxx>
29 #include <swtblfmt.hxx>
30 #include <tblsel.hxx>
31 
32 #include <unochart.hxx>
33 
35 {
36  GetFrameFormat()->GetDoc()->UpdateCharts( GetFrameFormat()->GetName() );
37 }
38 
39 bool SwTable::IsTableComplexForChart( const OUString& rSelection ) const
40 {
41  const SwTableBox* pSttBox, *pEndBox;
42  if( 2 < rSelection.getLength() )
43  {
44  const sal_Int32 nSeparator {rSelection.indexOf( ':' )};
45  OSL_ENSURE( -1 != nSeparator, "no valid selection" );
46 
47  // Remove brackets at the beginning and from the end
48  const sal_Int32 nOffset {'<' == rSelection[0] ? 1 : 0};
49  const sal_Int32 nLength {'>' == rSelection[ rSelection.getLength()-1 ]
50  ? rSelection.getLength()-1 : rSelection.getLength()};
51 
52  pSttBox = GetTableBox(rSelection.copy( nOffset, nSeparator - nOffset ));
53  pEndBox = GetTableBox(rSelection.copy( nSeparator+1, nLength - (nSeparator+1) ));
54  }
55  else
56  {
57  const SwTableLines* pLns = &GetTabLines();
58  pSttBox = (*pLns)[ 0 ]->GetTabBoxes().front();
59  while( !pSttBox->GetSttNd() )
60  // Until the Content Box!
61  pSttBox = pSttBox->GetTabLines().front()->GetTabBoxes().front();
62 
63  const SwTableBoxes* pBoxes = &pLns->back()->GetTabBoxes();
64  pEndBox = pBoxes->back();
65  while( !pEndBox->GetSttNd() )
66  {
67  // Until the Content Box!
68  pLns = &pEndBox->GetTabLines();
69  pBoxes = &pLns->back()->GetTabBoxes();
70  pEndBox = pBoxes->back();
71  }
72  }
73 
74  return !pSttBox || !pEndBox || !::ChkChartSel( *pSttBox->GetSttNd(),
75  *pEndBox->GetSttNd() );
76 }
77 
79 {
81  if( pVSh )
82  {
83  const SwFrameFormats& rTableFormats = *GetTableFrameFormats();
84  for( size_t n = 0; n < rTableFormats.size(); ++n )
85  {
86  SwTable* pTmpTable;
87  const SwTableNode* pTableNd;
88  const SwFrameFormat* pFormat = rTableFormats[ n ];
89 
90  if( nullptr != ( pTmpTable = SwTable::FindTable( pFormat ) ) &&
91  nullptr != ( pTableNd = pTmpTable->GetTableNode() ) &&
92  pTableNd->GetNodes().IsDocNodes() )
93  {
94  UpdateCharts_( *pTmpTable, *pVSh );
95  }
96  }
97  }
98 }
99 
100 void SwDoc::UpdateCharts_( const SwTable& rTable, SwViewShell const & rVSh ) const
101 {
102  OUString aName( rTable.GetFrameFormat()->GetName() );
103  SwStartNode *pStNd;
104  SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
105  while( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
106  {
107  ++aIdx;
108  SwOLENode *pONd;
109  if( nullptr != ( pONd = aIdx.GetNode().GetOLENode() ) &&
110  aName == pONd->GetChartTableName() &&
111  pONd->getLayoutFrame( rVSh.GetLayout() ) )
112  {
114  if (pPCD)
115  pPCD->InvalidateTable( &rTable );
116  // following this the framework will now take care of repainting
117  // the chart or it's replacement image...
118  }
119  aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
120  }
121 }
122 
123 void SwDoc::UpdateCharts( const OUString &rName ) const
124 {
125  SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) );
126  if( pTmpTable )
127  {
129 
130  if( pVSh )
131  UpdateCharts_( *pTmpTable, *pVSh );
132  }
133 }
134 
135 void SwDoc::SetTableName( SwFrameFormat& rTableFormat, const OUString &rNewName )
136 {
137  const OUString aOldName( rTableFormat.GetName() );
138 
139  bool bNameFound = rNewName.isEmpty();
140  if( !bNameFound )
141  {
142  const SwFrameFormats& rTable = *GetTableFrameFormats();
143  for( size_t i = rTable.size(); i; )
144  {
145  const SwFrameFormat* pFormat;
146  if( !( pFormat = rTable[ --i ] )->IsDefault() &&
147  pFormat->GetName() == rNewName && IsUsed( *pFormat ) )
148  {
149  bNameFound = true;
150  break;
151  }
152  }
153  }
154 
155  if( !bNameFound )
156  rTableFormat.SetName( rNewName, true );
157  else
158  rTableFormat.SetName( GetUniqueTableName(), true );
159 
160  SwStartNode *pStNd;
161  SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
162  while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
163  {
164  ++aIdx;
165  SwOLENode *pNd = aIdx.GetNode().GetOLENode();
166  if( pNd && aOldName == pNd->GetChartTableName() )
167  {
168  pNd->SetChartTableName( rNewName );
169 
170  SwTable* pTable = SwTable::FindTable( &rTableFormat );
172  if (pPCD)
173  pPCD->InvalidateTable( pTable );
174  // following this the framework will now take care of repainting
175  // the chart or it's replacement image...
176  }
177  aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
178  }
180 }
181 
182 /* 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:34
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:3845
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:1147
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
Definition: ndtbl.cxx:3897
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:419
void UpdateCharts_(const SwTable &rTable, SwViewShell const &rVSh) const
Definition: docchart.cxx:100
bool IsTableComplexForChart(const OUString &rSel) const
Definition: docchart.cxx:39
SwNode & GetNode() const
Definition: ndindex.hxx:119
void InvalidateTable(const SwTable *pTable)
Definition: unochart.cxx:1430
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:2454
void UpdateCharts(const OUString &rName) const
Definition: docchart.cxx:123
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:393
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:226
SwTableLines & GetTabLines()
Definition: swtable.hxx:198
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
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:84
SwNodes & GetNodes()
Definition: doc.hxx:402
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
void DoUpdateAllCharts()
Definition: docchart.cxx:78
void SetTableName(SwFrameFormat &rTableFormat, const OUString &rNewName)
Definition: docchart.cxx:135
OString const aName
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2334
size_t size() const
Definition: docary.hxx:225
sal_Int32 const nLength
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
SwNodeIndex & Assign(SwNodes const &rNds, sal_uLong)
Definition: ndindex.hxx:272
SwTableNode * GetTableNode() const
Definition: swtable.cxx:1927