LibreOffice Module chart2 (master) 1
ViewElementListProvider.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 <memory>
24#include <DrawViewWrapper.hxx>
25
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>
37
38namespace chart
39{
40using namespace ::com::sun::star;
41
43 : m_pDrawModelWrapper( pDrawModelWrapper )
44{
45}
46
48{
49 m_pDrawModelWrapper = rOther.m_pDrawModelWrapper;
50 m_pFontList = std::move(rOther.m_pFontList);
51}
52
54{
55}
56
58{
61 return XColorListRef();
62}
63
65{
68 return XDashListRef();
69}
70
72{
75 return XLineEndListRef();
76}
77
79{
82 return XGradientListRef();
83}
85{
88 return nullptr;
89}
90
92{
95 return XBitmapListRef();
96}
97
99{
102 return XPatternListRef();
103}
104
105//create chartspecific symbols for linecharts
107{
108 SdrObjList* pSymbolList = nullptr;
109 try
110 {
111 //@todo use mutex
112
113 //get hidden draw page (target):
115
116 //create symbols via uno and convert to native sdr objects
117 drawing::Direction3D aSymbolSize(220, 220, 0); // should be 250, but 250 -> 280 ??
120
122 uno::Reference<drawing::XShape>(static_cast<cppu::OWeakObject*>(xSymbols.get()), uno::UNO_QUERY));
123 if (pSdrObject)
124 pSymbolList = pSdrObject->GetSubList();
125 }
126 catch( const uno::Exception& )
127 {
128 TOOLS_WARN_EXCEPTION("chart2", "" );
129 }
130 return pSymbolList;
131}
132
133Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const
134{
135 SdrObjList* pSymbolList = GetSymbolList();
136 if( !pSymbolList->GetObjCount() )
137 return Graphic();
138 if(nStandardSymbol<0)
139 nStandardSymbol*=-1;
140 if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() )
141 nStandardSymbol %= pSymbolList->GetObjCount();
142 rtl::Reference<SdrObject> pObj = pSymbolList->GetObj(nStandardSymbol);
143
145 pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
146
147 std::unique_ptr<SdrModel> pModel(
148 new SdrModel());
149
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());
157
158 // directly clone to target SdrModel
159 pObj = pObj->CloneSdrObject(*pModel);
160
161 pPage->NbcInsertObject(pObj.get());
162 aView.MarkObj(pObj.get(),pPageView);
163 if( pSymbolShapeProperties )
164 pObj->SetMergedItemSet(*pSymbolShapeProperties);
165
166 GDIMetaFile aMeta(aView.GetMarkedObjMetaFile());
167
168 Graphic aGraph(aMeta);
169 Size aSize = pObj->GetSnapRect().GetSize();
170 aGraph.SetPrefSize(aSize);
171 aGraph.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
172
173 aView.UnmarkAll();
174 pObj=pPage->RemoveObject(0);
175 // these need to die before the associated SdrModel
176 pObj.clear();
177 pPage.clear();
178
179 return aGraph;
180}
181
183{
184 //was old chart:
185 //SvxFontListItem* SfxObjectShell::.GetItem(SID_ATTR_CHAR_FONTLIST)
186
187 if(!m_pFontList)
188 {
191 m_pFontList.reset( new FontList( pRefDev ? pRefDev : pDefaultOut
192 , pRefDev ? pDefaultOut : nullptr) );
193 }
194 return m_pFontList.get();
195}
196} //namespace chart
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OutputDevice * GetDefaultDevice()
void SetPrefMapMode(const MapMode &rPrefMapMode)
void SetPrefSize(const Size &rPrefSize)
GDIMetaFile GetMarkedObjMetaFile(bool bNoVDevIfOneMtfMarked=false) const
void hideMarkHandles()
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrPageView * ShowSdrPage(SdrPage *pPage) override
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
virtual SdrObjList * GetSubList() const
void UnmarkAll()
static rtl::Reference< SvxShapeGroup > create2DSymbolList(const rtl::Reference< SvxDrawPage > &xTarget, const css::drawing::Direction3D &rSize)
XDashListRef GetDashList() const
XColorListRef GetColorList() const
XGradientListRef GetGradientList() const
XPatternListRef GetPatternList() const
XBitmapListRef GetBitmapList() const
XLineEndListRef GetLineEndList() const
XHatchListRef GetHatchList() const
const rtl::Reference< SvxDrawPage > & getHiddenDrawPage()
OutputDevice * getReferenceDevice() const
static SdrObject * getSdrObject(const css::uno::Reference< css::drawing::XShape > &xShape)
XGradientListRef GetGradientList() const
ViewElementListProvider(DrawModelWrapper *pDrawModelWrapper)
std::unique_ptr< FontList > m_pFontList
Graphic GetSymbolGraphic(sal_Int32 nStandardSymbol, const SfxItemSet *pSymbolShapeProperties) const
#define TOOLS_WARN_EXCEPTION(area, stream)
Reference< XInterface > xTarget
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)