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 for(const SwTableFormat* pFormat: *GetTableFrameFormats())
85 {
86 if( SwTable* pTmpTable = SwTable::FindTable( pFormat ) )
87 if( const SwTableNode* pTableNd = pTmpTable->GetTableNode() )
88 if( pTableNd->GetNodes().IsDocNodes() )
89 {
90 UpdateCharts_( *pTmpTable, *pVSh );
91 }
92 }
93}
94
95void SwDoc::UpdateCharts_( const SwTable& rTable, SwViewShell const & rVSh ) const
96{
97 OUString aName( rTable.GetFrameFormat()->GetName() );
98 SwStartNode *pStNd;
99 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
100 while( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
101 {
102 ++aIdx;
103 SwOLENode *pONd = aIdx.GetNode().GetOLENode();
104 if( pONd &&
105 aName == pONd->GetChartTableName() &&
106 pONd->getLayoutFrame( rVSh.GetLayout() ) )
107 {
108 // tdf#122995 for OLE/Charts in SW we do not (yet) have a refresh
109 // mechanism or embedding of the primitive representation, so this
110 // needs to be done locally here (simplest solution).
111 bool bImmediateMode(false);
112
113 if(pONd->IsChart())
114 {
115 // refresh to trigger repaint
116 const SwRect aChartRect(pONd->FindLayoutRect());
117 if(!aChartRect.IsEmpty())
118 const_cast<SwViewShell &>(rVSh).InvalidateWindows(aChartRect);
119
120 // forced refresh of the chart's primitive representation
122
123 // InvalidateTable using the Immediate-Mode, else the chart will
124 // not yet know that it is invalidated at the next repaint and create
125 // the same graphical representation again
126 bImmediateMode = true;
127 }
128
130 if (pPCD)
131 pPCD->InvalidateTable( &rTable, bImmediateMode );
132 // following this the framework will now take care of repainting
133 // the chart or it's replacement image...
134 }
135 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
136 }
137}
138
139void SwDoc::UpdateCharts( const OUString& rName ) const
140{
141 SwTable* pTmpTable = SwTable::FindTable( FindTableFormatByName( rName ) );
142 if( pTmpTable )
143 {
145
146 if( pVSh )
147 UpdateCharts_( *pTmpTable, *pVSh );
148 }
149}
150
151void SwDoc::SetTableName( SwFrameFormat& rTableFormat, const OUString &rNewName )
152{
153 const OUString aOldName( rTableFormat.GetName() );
154
155 bool bNameFound = rNewName.isEmpty();
156 if( !bNameFound )
157 {
158 for(const SwTableFormat* pFormat: *GetTableFrameFormats())
159 {
160 if( !pFormat->IsDefault() &&
161 pFormat->GetName() == rNewName && IsUsed( *pFormat ) )
162 {
163 bNameFound = true;
164 break;
165 }
166 }
167 }
168
169 if( !bNameFound )
170 rTableFormat.SetFormatName( rNewName, true );
171 else
172 rTableFormat.SetFormatName( GetUniqueTableName(), true );
173
174 SwStartNode *pStNd;
175 SwNodeIndex aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
176 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
177 {
178 ++aIdx;
179 SwOLENode *pNd = aIdx.GetNode().GetOLENode();
180 if( pNd && aOldName == pNd->GetChartTableName() )
181 {
182 pNd->SetChartTableName( rNewName );
183
184 SwTable* pTable = SwTable::FindTable( &rTableFormat );
186 if (pPCD)
187 pPCD->InvalidateTable( pTable );
188 // following this the framework will now take care of repainting
189 // the chart or it's replacement image...
190 }
191 aIdx.Assign( *pStNd->EndOfSectionNode(), + 1 );
192 }
194}
195
196/* 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:1434
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1223
SwRect FindLayoutRect(const bool bPrtArea=false, const Point *pPoint=nullptr) const
Definition: node.cxx:1231
void UpdateCharts(const OUString &rName) const
Definition: docchart.cxx:139
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:408
IDocumentChartDataProviderAccess const & getIDocumentChartDataProviderAccess() const
Definition: doc.cxx:241
const sw::TableFrameFormats * GetTableFrameFormats() const
Definition: doc.hxx:826
bool IsUsed(const sw::BroadcastingModify &) const
Definition: poolfmt.cxx:86
void SetTableName(SwFrameFormat &rTableFormat, const OUString &rNewName)
Definition: docchart.cxx:151
void DoUpdateAllCharts()
Definition: docchart.cxx:78
SwNodes & GetNodes()
Definition: doc.hxx:422
void UpdateCharts_(const SwTable &rTable, SwViewShell const &rVSh) const
Definition: docchart.cxx:95
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
SwTableFormat * FindTableFormatByName(const OUString &rName, bool bAll=false) const
Definition: ndtbl.cxx:3959
OUString GetUniqueTableName() const
Definition: ndtbl.cxx:3907
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:72
virtual void SetFormatName(const OUString &rNewName, bool bBroadcast=false) override
Definition: atrfrm.cxx:2608
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset nIdx)
Definition: ndindex.hxx:114
SwStartNode * GetStartNode()
Definition: node.hxx:642
SwOLENode * GetOLENode()
Inline methods from Node.hxx.
Definition: ndole.hxx:165
SwTableNode * GetTableNode()
Definition: node.hxx:650
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:695
bool IsChart() const
Definition: ndole.cxx:703
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:1238
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:443
SwTableLines & GetTabLines()
Definition: swtable.hxx:474
const SwStartNode * GetSttNd() const
Definition: swtable.hxx:495
SwTableBoxes & GetTabBoxes()
Definition: swtable.hxx:386
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:206
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:209
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:1344
static SwTable * FindTable(SwFrameFormat const *const pFormat)
Definition: swtable.cxx:2308
void UpdateCharts() const
Definition: docchart.cxx:34
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
virtual OUString GetName() const override
float u
OUString aName
std::vector< SwTableBox * > SwTableBoxes
Definition: swtable.hxx:105
bool ChkChartSel(const SwNode &rSttNd, const SwNode &rEndNd)
Definition: tblsel.cxx:426
sal_Int32 nLength