1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <IDocumentChartDataProviderAccess.hxx>
22 #include <IDocumentState.hxx>
23 #include <IDocumentLayoutAccess.hxx>
24 #include <ndindex.hxx>
25 #include <swtable.hxx>
28 #include <swtblfmt.hxx>
30 #include <frameformats.hxx>
31 #include <unochart.hxx>
32 #include <osl/diagnose.h>
34 void SwTable::UpdateCharts() const
36 GetFrameFormat()->GetDoc()->UpdateCharts( GetFrameFormat()->GetName() );
39 bool SwTable::IsTableComplexForChart( std::u16string_view aSelection
) const
41 const SwTableBox
* pSttBox
, *pEndBox
;
42 if( 2 < aSelection
.size() )
44 const size_t nSeparator
= aSelection
.find( u
':' );
45 OSL_ENSURE( std::u16string_view::npos
!= nSeparator
, "no valid selection" );
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();
52 pSttBox
= GetTableBox(OUString(aSelection
.substr( nOffset
, nSeparator
- nOffset
)));
53 pEndBox
= GetTableBox(OUString(aSelection
.substr( nSeparator
+1, nLength
- (nSeparator
+1) )));
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();
63 const SwTableBoxes
* pBoxes
= &pLns
->back()->GetTabBoxes();
64 pEndBox
= pBoxes
->back();
65 while( !pEndBox
->GetSttNd() )
67 // Until the Content Box!
68 pLns
= &pEndBox
->GetTabLines();
69 pBoxes
= &pLns
->back()->GetTabBoxes();
70 pEndBox
= pBoxes
->back();
74 return !pSttBox
|| !pEndBox
|| !::ChkChartSel( *pSttBox
->GetSttNd(),
75 *pEndBox
->GetSttNd() );
78 void SwDoc::DoUpdateAllCharts()
80 SwViewShell
* pVSh
= getIDocumentLayoutAccess().GetCurrentViewShell();
84 for(const SwTableFormat
* pFormat
: *GetTableFrameFormats())
86 if( SwTable
* pTmpTable
= SwTable::FindTable( pFormat
) )
87 if( const SwTableNode
* pTableNd
= pTmpTable
->GetTableNode() )
88 if( pTableNd
->GetNodes().IsDocNodes() )
90 UpdateCharts_( *pTmpTable
, *pVSh
);
95 void SwDoc::UpdateCharts_( const SwTable
& rTable
, SwViewShell
const & rVSh
) const
97 OUString
aName( rTable
.GetFrameFormat()->GetName() );
99 SwNodeIndex
aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
100 while( nullptr != (pStNd
= aIdx
.GetNode().GetStartNode()) )
103 SwOLENode
*pONd
= aIdx
.GetNode().GetOLENode();
105 aName
== pONd
->GetChartTableName() &&
106 pONd
->getLayoutFrame( rVSh
.GetLayout() ) )
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);
115 // refresh to trigger repaint
116 const SwRect
aChartRect(pONd
->FindLayoutRect());
117 if(!aChartRect
.IsEmpty())
118 const_cast<SwViewShell
&>(rVSh
).InvalidateWindows(aChartRect
);
120 // forced refresh of the chart's primitive representation
121 pONd
->GetOLEObj().resetBufferedData();
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;
129 SwChartDataProvider
*pPCD
= getIDocumentChartDataProviderAccess().GetChartDataProvider();
131 pPCD
->InvalidateTable( &rTable
, bImmediateMode
);
132 // following this the framework will now take care of repainting
133 // the chart or it's replacement image...
135 aIdx
.Assign( *pStNd
->EndOfSectionNode(), + 1 );
139 void SwDoc::UpdateCharts( const OUString
& rName
) const
141 SwTable
* pTmpTable
= SwTable::FindTable( FindTableFormatByName( rName
) );
144 SwViewShell
const * pVSh
= getIDocumentLayoutAccess().GetCurrentViewShell();
147 UpdateCharts_( *pTmpTable
, *pVSh
);
151 void SwDoc::SetTableName( SwFrameFormat
& rTableFormat
, const OUString
&rNewName
)
153 const OUString
aOldName( rTableFormat
.GetName() );
155 bool bNameFound
= rNewName
.isEmpty();
158 for(const SwTableFormat
* pFormat
: *GetTableFrameFormats())
160 if( !pFormat
->IsDefault() &&
161 pFormat
->GetName() == rNewName
&& IsUsed( *pFormat
) )
170 rTableFormat
.SetFormatName( rNewName
, true );
172 rTableFormat
.SetFormatName( GetUniqueTableName(), true );
175 SwNodeIndex
aIdx( *GetNodes().GetEndOfAutotext().StartOfSectionNode(), 1 );
176 while ( nullptr != (pStNd
= aIdx
.GetNode().GetStartNode()) )
179 SwOLENode
*pNd
= aIdx
.GetNode().GetOLENode();
180 if( pNd
&& aOldName
== pNd
->GetChartTableName() )
182 pNd
->SetChartTableName( rNewName
);
184 SwTable
* pTable
= SwTable::FindTable( &rTableFormat
);
185 SwChartDataProvider
*pPCD
= getIDocumentChartDataProviderAccess().GetChartDataProvider();
187 pPCD
->InvalidateTable( pTable
);
188 // following this the framework will now take care of repainting
189 // the chart or it's replacement image...
191 aIdx
.Assign( *pStNd
->EndOfSectionNode(), + 1 );
193 getIDocumentState().SetModified();
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */