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 <ndindex.hxx>
25#include <swtable.hxx>
26#include <viewsh.hxx>
27#include <ndole.hxx>
28#include <swtblfmt.hxx>
29#include <tblsel.hxx>
30#include <frameformats.hxx>
31#include <unochart.hxx>
32#include <osl/diagnose.h>
33
35{
37}
38
39bool SwTable::IsTableComplexForChart( std::u16string_view aSelection ) const
40{
41 const SwTableBox* pSttBox, *pEndBox;
42 if( 2 < aSelection.size() )
43 {
44 const size_t nSeparator = aSelection.find( u':' );
45 OSL_ENSURE( std::u16string_view::npos != nSeparator, "no valid selection" );
46
47 // Remove brackets at the beginning and from the end
48 const sal_Int32 nOffset = '<' == aSelection[0] ? 1 : 0;
49 const sal_Int32 nLength = '>' == aSelection[ aSelection.size()-1 ]
50 ? aSelection.size()-1 : aSelection.size();
51
52 pSttBox = GetTableBox(OUString(aSelection.substr( nOffset, nSeparator - nOffset )));
53 pEndBox = GetTableBox(OUString(aSelection.substr( 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 return;
83
84 const SwFrameFormats& rTableFormats = *GetTableFrameFormats();
85 for( size_t n = 0; n < rTableFormats.size(); ++n )
86 {
87 const SwFrameFormat* pFormat = rTableFormats[ n ];
88 if( SwTable* pTmpTable = SwTable::FindTable( pFormat ) )
89 if( const SwTableNode* pTableNd = pTmpTable->GetTableNode() )
90 if( pTableNd->GetNodes().IsDocNodes() )
91 {
92 UpdateCharts_( *pTmpTable, *pVSh );
93 }
94 }
95}
96
97void SwDoc::UpdateCharts_( const SwTable& rTable, SwViewShell const & rVSh ) const
98{
99 OUString aName( rTable.GetFrameFormat()->GetName() );
100 SwStartNode *pStNd;
101 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
102 while( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
103 {
104 ++aIdx;
105 SwOLENode *pONd = aIdx.GetNode().GetOLENode();
106 if( pONd &&
107 aName == pONd->GetChartTableName() &&
108 pONd->getLayoutFrame( rVSh.GetLayout() ) )
109 {
110 // tdf#122995 for OLE/Charts in SW we do not (yet) have a refresh
111 // mechanism or embedding of the primitive representation, so this
112 // needs to be done locally here (simplest solution).
113 bool bImmediateMode(false);
114
115 if(pONd->IsChart())
116 {
117 // refresh to trigger repaint
118 const SwRect aChartRect(pONd->FindLayoutRect());
119 if(!aChartRect.IsEmpty())
120 const_cast<SwViewShell &>(rVSh).InvalidateWindows(aChartRect);
121
122 // forced refresh of the chart's primitive representation
124
125 // InvalidateTable using the Immediate-Mode, else the chart will
126 // not yet know that it is invalidated at the next repaint and create
127 // the same graphical representation again
128 bImmediateMode = true;
129 }
130
132 if (pPCD)
133 pPCD->InvalidateTable( &rTable, bImmediateMode );
134 // following this the framework will now take care of repainting
135 // the chart or it's replacement image...
136 }
137 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
138 }
139}
140
141void SwDoc::UpdateCharts( const OUString& rName ) const
142{
143 SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) );
144 if( pTmpTable )
145 {
147
148 if( pVSh )
149 UpdateCharts_( *pTmpTable, *pVSh );
150 }
151}
152
153void SwDoc::SetTableName( SwFrameFormat& rTableFormat, const OUString &rNewName )
154{
155 const OUString aOldName( rTableFormat.GetName() );
156
157 bool bNameFound = rNewName.isEmpty();
158 if( !bNameFound )
159 {
160 const SwFrameFormats& rTable = *GetTableFrameFormats();
161 for( size_t i = rTable.size(); i; )
162 {
163 const SwFrameFormat* pFormat = rTable[ --i ];
164 if( !pFormat->IsDefault() &&
165 pFormat->GetName() == rNewName && IsUsed( *pFormat ) )
166 {
167 bNameFound = true;
168 break;
169 }
170 }
171 }
172
173 if( !bNameFound )
174 rTableFormat.SetFormatName( rNewName, true );
175 else
176 rTableFormat.SetFormatName( GetUniqueTableName(), true );
177
178 SwStartNode *pStNd;
179 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
180 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
181 {
182 ++aIdx;
183 SwOLENode *pNd = aIdx.GetNode().GetOLENode();
184 if( pNd && aOldName == pNd->GetChartTableName() )
185 {
186 pNd->SetChartTableName( rNewName );
187
188 SwTable* pTable = SwTable::FindTable( &rTableFormat );
190 if (pPCD)
191 pPCD->InvalidateTable( pTable );
192 // following this the framework will now take care of repainting
193 // the chart or it's replacement image...
194 }
195 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
196 }
198}
199
200/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwChartDataProvider * GetChartDataProvider(bool bCreate=false) const =0
returns or creates the data-provider for chart
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
virtual void SetModified()=0
Must be called manually at changes of format.
void InvalidateTable(const SwTable *pTable, bool bImmediate=false)
Definition: unochart.cxx:1431
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1230
SwRect FindLayoutRect(const bool bPrtArea=false, const Point *pPoint=nullptr) const
Definition: node.cxx:1238
void UpdateCharts(const OUString &rName) const
Definition: docchart.cxx:141
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:400
IDocumentChartDataProviderAccess const & getIDocumentChartDataProviderAccess() const
Definition: doc.cxx:233
bool IsUsed(const sw::BroadcastingModify &) const
Definition: poolfmt.cxx:86
void SetTableName(SwFrameFormat &rTableFormat, const OUString &rNewName)
Definition: docchart.cxx:153
void DoUpdateAllCharts()
Definition: docchart.cxx:78
SwNodes & GetNodes()
Definition: doc.hxx:417
void UpdateCharts_(const SwTable &rTable, SwViewShell const &rVSh) const
Definition: docchart.cxx:97
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:411
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
Definition: ndtbl.cxx:3941
OUString GetUniqueTableName() const
Definition: ndtbl.cxx:3889
const SwFrameFormats * GetTableFrameFormats() const
Definition: doc.hxx:819
bool IsDefault() const
Definition: format.hxx:129
const SwDoc * GetDoc() const
The document is set in SwAttrPool now, therefore you always can access it.
Definition: format.hxx:139
const OUString & GetName() const
Definition: format.hxx:131
Style of a layout element.
Definition: frmfmt.hxx:62
virtual void SetFormatName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2593
Specific frame formats (frames, DrawObjects).
size_t size() const
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset)
Definition: ndindex.hxx:291
SwNode & GetNode() const
Definition: ndindex.hxx:136
SwStartNode * GetStartNode()
Definition: node.hxx:640
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:165
SwTableNode * GetTableNode()
Definition: node.hxx:648
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:731
bool IsChart() const
Definition: ndole.cxx:633
const SwOLEObj & GetOLEObj() const
Definition: ndole.hxx:116
void SetChartTableName(const OUString &rNm)
Definition: ndole.hxx:157
const OUString & GetChartTableName() const
Definition: ndole.hxx:156
void resetBufferedData()
Definition: ndole.cxx:1168
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
bool IsEmpty() const
Definition: swrect.hxx:304
Starts a section of nodes in the document model.
Definition: node.hxx:348
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:426
SwTableLines & GetTabLines()
Definition: swtable.hxx:457
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:478
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:374
SwTableLine * back() const
Definition: swtable.hxx:82
SwTableLine * front() const
Definition: swtable.hxx:81
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
SwTableLines & GetTabLines()
Definition: swtable.hxx:204
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:207
bool IsTableComplexForChart(std::u16string_view aSel) const
Definition: docchart.cxx:39
const SwTableBox * GetTableBox(const OUString &rName, const bool bPerformValidCheck=false) const
Definition: swtable.cxx:1340
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:2135
void UpdateCharts() const
Definition: docchart.cxx:34
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2160
virtual OUString GetName() const override
float u
OUString aName
sal_Int64 n
int i
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:105
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:426
sal_Int32 nLength