nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / controller / drawinglayer / ViewElementListProvider.cxx
blob9259ce92181947a095d00f533680792e94984cc1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <memory>
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 <tools/diagnose_ex.h>
38 namespace chart
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();
88 return nullptr;
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;
111 //@todo use mutex
113 //get shape factory
114 uno::Reference<lang::XMultiServiceFactory> xShapeFactory(
115 m_pDrawModelWrapper->getShapeFactory());
117 //get hidden draw page (target):
118 uno::Reference<drawing::XShapes> xTarget = m_pDrawModelWrapper->getHiddenDrawPage();
120 //create symbols via uno and convert to native sdr objects
121 drawing::Direction3D aSymbolSize(220, 220, 0); // should be 250, but 250 -> 280 ??
122 uno::Reference<drawing::XShapes> xSymbols
123 = DataPointSymbolSupplier::create2DSymbolList(xShapeFactory, xTarget, aSymbolSize);
125 SdrObject* pSdrObject = DrawViewWrapper::getSdrObject(
126 uno::Reference<drawing::XShape>(xSymbols, uno::UNO_QUERY));
127 if (pSdrObject)
128 pSymbolList = pSdrObject->GetSubList();
130 catch( const uno::Exception& )
132 TOOLS_WARN_EXCEPTION("chart2", "" );
134 return pSymbolList;
137 Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const
139 SdrObjList* pSymbolList = GetSymbolList();
140 if( !pSymbolList->GetObjCount() )
141 return Graphic();
142 if(nStandardSymbol<0)
143 nStandardSymbol*=-1;
144 if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() )
145 nStandardSymbol %= pSymbolList->GetObjCount();
146 SdrObject* pObj = pSymbolList->GetObj(nStandardSymbol);
148 ScopedVclPtrInstance< VirtualDevice > pVDev;
149 pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
151 std::unique_ptr<SdrModel> pModel(
152 new SdrModel());
154 pModel->GetItemPool().FreezeIdRanges();
155 SdrPage* pPage = new SdrPage( *pModel, false );
156 pPage->SetSize(Size(1000,1000));
157 pModel->InsertPage( pPage, 0 );
158 std::unique_ptr<SdrView> pView(new SdrView(*pModel, pVDev));
159 pView->hideMarkHandles();
160 SdrPageView* pPageView = pView->ShowSdrPage(pPage);
162 // directly clone to target SdrModel
163 pObj = pObj->CloneSdrObject(*pModel);
165 pPage->NbcInsertObject(pObj);
166 pView->MarkObj(pObj,pPageView);
167 if( pSymbolShapeProperties )
168 pObj->SetMergedItemSet(*pSymbolShapeProperties);
170 GDIMetaFile aMeta(pView->GetMarkedObjMetaFile());
172 Graphic aGraph(aMeta);
173 Size aSize = pObj->GetSnapRect().GetSize();
174 aGraph.SetPrefSize(aSize);
175 aGraph.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
177 pView->UnmarkAll();
178 pObj=pPage->RemoveObject(0);
179 SdrObject::Free( pObj );
181 return aGraph;
184 FontList* ViewElementListProvider::getFontList() const
186 //was old chart:
187 //SvxFontListItem* SfxObjectShell::.GetItem(SID_ATTR_CHAR_FONTLIST)
189 if(!m_pFontList)
191 OutputDevice* pRefDev = m_pDrawModelWrapper ? m_pDrawModelWrapper->getReferenceDevice() : nullptr;
192 OutputDevice* pDefaultOut = Application::GetDefaultDevice();
193 m_pFontList.reset( new FontList( pRefDev ? pRefDev : pDefaultOut
194 , pRefDev ? pDefaultOut : nullptr) );
196 return m_pFontList.get();
198 } //namespace chart
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */