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 <ViewElementListProvider.hxx>
22 #include <chartview/DrawModelWrapper.hxx>
23 #include <chartview/DataPointSymbolSupplier.hxx>
24 #include <DrawViewWrapper.hxx>
26 #include <com/sun/star/drawing/Direction3D.hpp>
27 #include <o3tl/safeint.hxx>
28 #include <svx/xtable.hxx>
29 #include <svl/itempool.hxx>
30 #include <svtools/ctrltool.hxx>
31 #include <vcl/svapp.hxx>
32 #include <svx/svdobj.hxx>
33 #include <vcl/virdev.hxx>
34 #include <svx/svdview.hxx>
35 #include <svx/svdpage.hxx>
36 #include <comphelper/diagnose_ex.hxx>
40 using namespace ::com::sun::star
;
42 ViewElementListProvider::ViewElementListProvider( DrawModelWrapper
* pDrawModelWrapper
)
43 : m_pDrawModelWrapper( pDrawModelWrapper
)
47 ViewElementListProvider::ViewElementListProvider(ViewElementListProvider
&& rOther
) noexcept
49 m_pDrawModelWrapper
= rOther
.m_pDrawModelWrapper
;
50 m_pFontList
= std::move(rOther
.m_pFontList
);
53 ViewElementListProvider::~ViewElementListProvider()
57 XColorListRef
ViewElementListProvider::GetColorTable() const
59 if(m_pDrawModelWrapper
)
60 return m_pDrawModelWrapper
->GetColorList();
61 return XColorListRef();
64 XDashListRef
ViewElementListProvider::GetDashList() const
66 if(m_pDrawModelWrapper
)
67 return m_pDrawModelWrapper
->GetDashList();
68 return XDashListRef();
71 XLineEndListRef
ViewElementListProvider::GetLineEndList() const
73 if(m_pDrawModelWrapper
)
74 return m_pDrawModelWrapper
->GetLineEndList();
75 return XLineEndListRef();
78 XGradientListRef
ViewElementListProvider::GetGradientList() const
80 if(m_pDrawModelWrapper
)
81 return m_pDrawModelWrapper
->GetGradientList();
82 return XGradientListRef();
84 XHatchListRef
ViewElementListProvider::GetHatchList() const
86 if(m_pDrawModelWrapper
)
87 return m_pDrawModelWrapper
->GetHatchList();
91 XBitmapListRef
ViewElementListProvider::GetBitmapList() const
93 if(m_pDrawModelWrapper
)
94 return m_pDrawModelWrapper
->GetBitmapList();
95 return XBitmapListRef();
98 XPatternListRef
ViewElementListProvider::GetPatternList() const
100 if(m_pDrawModelWrapper
)
101 return m_pDrawModelWrapper
->GetPatternList();
102 return XPatternListRef();
105 //create chartspecific symbols for linecharts
106 SdrObjList
* ViewElementListProvider::GetSymbolList() const
108 SdrObjList
* pSymbolList
= nullptr;
113 //get hidden draw page (target):
114 rtl::Reference
<SvxDrawPage
> xTarget
= m_pDrawModelWrapper
->getHiddenDrawPage();
116 //create symbols via uno and convert to native sdr objects
117 drawing::Direction3D
aSymbolSize(220, 220, 0); // should be 250, but 250 -> 280 ??
118 rtl::Reference
< SvxShapeGroup
> xSymbols
119 = DataPointSymbolSupplier::create2DSymbolList(xTarget
, aSymbolSize
);
121 SdrObject
* pSdrObject
= DrawViewWrapper::getSdrObject(
122 uno::Reference
<drawing::XShape
>(static_cast<cppu::OWeakObject
*>(xSymbols
.get()), uno::UNO_QUERY
));
124 pSymbolList
= pSdrObject
->GetSubList();
126 catch( const uno::Exception
& )
128 TOOLS_WARN_EXCEPTION("chart2", "" );
133 Graphic
ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol
, const SfxItemSet
* pSymbolShapeProperties
) const
135 SdrObjList
* pSymbolList
= GetSymbolList();
136 if( !pSymbolList
->GetObjCount() )
138 if(nStandardSymbol
<0)
140 if( o3tl::make_unsigned(nStandardSymbol
) >= pSymbolList
->GetObjCount() )
141 nStandardSymbol
%= pSymbolList
->GetObjCount();
142 rtl::Reference
<SdrObject
> pObj
= pSymbolList
->GetObj(nStandardSymbol
);
144 ScopedVclPtrInstance
< VirtualDevice
> pVDev
;
145 pVDev
->SetMapMode(MapMode(MapUnit::Map100thMM
));
147 std::unique_ptr
<SdrModel
> pModel(
150 pModel
->GetItemPool().FreezeIdRanges();
151 rtl::Reference
<SdrPage
> pPage
= new SdrPage( *pModel
, false );
152 pPage
->SetSize(Size(1000,1000));
153 pModel
->InsertPage( pPage
.get(), 0 );
154 SdrView
aView(*pModel
, pVDev
);
155 aView
.hideMarkHandles();
156 SdrPageView
* pPageView
= aView
.ShowSdrPage(pPage
.get());
158 // directly clone to target SdrModel
159 pObj
= pObj
->CloneSdrObject(*pModel
);
161 pPage
->NbcInsertObject(pObj
.get());
162 aView
.MarkObj(pObj
.get(),pPageView
);
163 if( pSymbolShapeProperties
)
164 pObj
->SetMergedItemSet(*pSymbolShapeProperties
);
166 GDIMetaFile
aMeta(aView
.GetMarkedObjMetaFile());
168 Graphic
aGraph(aMeta
);
169 Size aSize
= pObj
->GetSnapRect().GetSize();
170 aGraph
.SetPrefSize(aSize
);
171 aGraph
.SetPrefMapMode(MapMode(MapUnit::Map100thMM
));
174 pObj
=pPage
->RemoveObject(0);
175 // these need to die before the associated SdrModel
182 FontList
* ViewElementListProvider::getFontList() const
185 //SvxFontListItem* SfxObjectShell::.GetItem(SID_ATTR_CHAR_FONTLIST)
189 OutputDevice
* pRefDev
= m_pDrawModelWrapper
? m_pDrawModelWrapper
->getReferenceDevice() : nullptr;
190 OutputDevice
* pDefaultOut
= Application::GetDefaultDevice();
191 m_pFontList
.reset( new FontList( pRefDev
? pRefDev
: pDefaultOut
192 , pRefDev
? pDefaultOut
: nullptr) );
194 return m_pFontList
.get();
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */