| 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> |
| 21 |
#include <ViewElementListProvider.hxx> |
| 22 |
#include <chartview/DrawModelWrapper.hxx> |
| 23 |
#include <chartview/DataPointSymbolSupplier.hxx> |
| 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 <svtools/ctrltool.hxx> |
| 30 |
#include <vcl/svapp.hxx> |
| 31 |
#include <svx/svdobj.hxx> |
| 32 |
#include <vcl/virdev.hxx> |
| 33 |
#include <svx/svdview.hxx> |
| 34 |
#include <svx/svdpage.hxx> |
| 35 |
#include <comphelper/diagnose_ex.hxx> |
| 36 |
|
| 37 |
namespace chart |
| 38 |
{ |
| 39 |
using namespace ::com::sun::star; |
| 40 |
|
| 41 |
ViewElementListProvider::ViewElementListProvider( DrawModelWrapper* pDrawModelWrapper ) |
| 42 |
: m_pDrawModelWrapper( pDrawModelWrapper ) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
ViewElementListProvider::ViewElementListProvider(ViewElementListProvider&& rOther) noexcept |
| 47 |
{ |
| 48 |
m_pDrawModelWrapper = rOther.m_pDrawModelWrapper; |
| 49 |
m_pFontList = std::move(rOther.m_pFontList); |
| 50 |
} |
| 51 |
|
| 52 |
ViewElementListProvider::~ViewElementListProvider() |
| 53 |
{ |
| 54 |
} |
| 55 |
|
| 56 |
XColorListRef ViewElementListProvider::GetColorTable() const |
| 57 |
{ |
| 58 |
if(m_pDrawModelWrapper) |
| 59 |
return m_pDrawModelWrapper->GetColorList(); |
| 60 |
return XColorListRef(); |
| 61 |
} |
| 62 |
|
| 63 |
XDashListRef ViewElementListProvider::GetDashList() const |
| 64 |
{ |
| 65 |
if(m_pDrawModelWrapper) |
| 66 |
return m_pDrawModelWrapper->GetDashList(); |
| 67 |
return XDashListRef(); |
| 68 |
} |
| 69 |
|
| 70 |
XLineEndListRef ViewElementListProvider::GetLineEndList() const |
| 71 |
{ |
| 72 |
if(m_pDrawModelWrapper) |
| 73 |
return m_pDrawModelWrapper->GetLineEndList(); |
| 74 |
return XLineEndListRef(); |
| 75 |
} |
| 76 |
|
| 77 |
XGradientListRef ViewElementListProvider::GetGradientList() const |
| 78 |
{ |
| 79 |
if(m_pDrawModelWrapper) |
| 80 |
return m_pDrawModelWrapper->GetGradientList(); |
| 81 |
return XGradientListRef(); |
| 82 |
} |
| 83 |
XHatchListRef ViewElementListProvider::GetHatchList() const |
| 84 |
{ |
| 85 |
if(m_pDrawModelWrapper) |
| 86 |
return m_pDrawModelWrapper->GetHatchList(); |
| 87 |
return nullptr; |
| 88 |
} |
| 89 |
|
| 90 |
XBitmapListRef ViewElementListProvider::GetBitmapList() const |
| 91 |
{ |
| 92 |
if(m_pDrawModelWrapper) |
| 93 |
return m_pDrawModelWrapper->GetBitmapList(); |
| 94 |
return XBitmapListRef(); |
| 95 |
} |
| 96 |
|
| 97 |
XPatternListRef ViewElementListProvider::GetPatternList() const |
| 98 |
{ |
| 99 |
if(m_pDrawModelWrapper) |
| 100 |
return m_pDrawModelWrapper->GetPatternList(); |
| 101 |
return XPatternListRef(); |
| 102 |
} |
| 103 |
|
| 104 |
//create chartspecific symbols for linecharts |
| 105 |
SdrObjList* ViewElementListProvider::GetSymbolList() const |
| 106 |
{ |
| 107 |
SdrObjList* pSymbolList = nullptr; |
| 108 |
try |
| 109 |
{ |
| 110 |
//@todo use mutex |
| 111 |
|
| 112 |
//get hidden draw page (target): |
| 113 |
rtl::Reference<SvxDrawPage> xTarget = m_pDrawModelWrapper->getHiddenDrawPage(); |
| 114 |
|
| 115 |
//create symbols via uno and convert to native sdr objects |
| 116 |
drawing::Direction3D aSymbolSize(220, 220, 0); // should be 250, but 250 -> 280 ?? |
| 117 |
rtl::Reference< SvxShapeGroup > xSymbols |
| 118 |
= DataPointSymbolSupplier::create2DSymbolList(xTarget, aSymbolSize); |
| 119 |
|
| 120 |
SdrObject* pSdrObject = DrawViewWrapper::getSdrObject( |
| 121 |
uno::Reference<drawing::XShape>(static_cast<cppu::OWeakObject*>(xSymbols.get()), uno::UNO_QUERY)); |
| 122 |
if (pSdrObject) |
| 123 |
pSymbolList = pSdrObject->GetSubList(); |
| 124 |
} |
| 125 |
catch( const uno::Exception& ) |
| 126 |
{ |
| 127 |
TOOLS_WARN_EXCEPTION("chart2", "" ); |
| 128 |
} |
| 129 |
return pSymbolList; |
| 130 |
} |
| 131 |
|
| 132 |
Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const |
| 133 |
{ |
| 134 |
SdrObjList* pSymbolList = GetSymbolList(); |
| 135 |
if( !pSymbolList->GetObjCount() ) |
| 136 |
return Graphic(); |
| 137 |
if(nStandardSymbol<0) |
| 138 |
nStandardSymbol*=-1; |
| 139 |
if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() ) |
| 140 |
nStandardSymbol %= pSymbolList->GetObjCount(); |
| 141 |
rtl::Reference<SdrObject> pObj = pSymbolList->GetObj(nStandardSymbol); |
| 142 |
|
| 143 |
ScopedVclPtrInstance< VirtualDevice > pVDev; |
| 144 |
pVDev->SetMapMode(MapMode(MapUnit::Map100thMM)); |
| 145 |
|
| 146 |
std::unique_ptr<SdrModel> pModel( |
| 147 |
new SdrModel()); |
| 148 |
|
| 149 |
rtl::Reference<SdrPage> pPage = new SdrPage( *pModel, false ); |
| 150 |
pPage->SetSize(Size(1000,1000)); |
| 151 |
pModel->InsertPage( pPage.get(), 0 ); |
| 152 |
SdrView aView(*pModel, pVDev); |
| 153 |
aView.hideMarkHandles(); |
| 154 |
SdrPageView* pPageView = aView.ShowSdrPage(pPage.get()); |
| 155 |
|
| 156 |
// directly clone to target SdrModel |
| 157 |
pObj = pObj->CloneSdrObject(*pModel); |
| 158 |
|
| 159 |
pPage->NbcInsertObject(pObj.get()); |
| 160 |
aView.MarkObj(pObj.get(),pPageView); |
| 161 |
if( pSymbolShapeProperties ) |
| 162 |
pObj->SetMergedItemSet(*pSymbolShapeProperties); |
| 163 |
|
| 164 |
GDIMetaFile aMeta(aView.GetMarkedObjMetaFile()); |
| 165 |
|
| 166 |
Graphic aGraph(aMeta); |
| 167 |
Size aSize = pObj->GetSnapRect().GetSize(); |
| 168 |
aGraph.SetPrefSize(aSize); |
| 169 |
aGraph.SetPrefMapMode(MapMode(MapUnit::Map100thMM)); |
| 170 |
|
| 171 |
aView.UnmarkAll(); |
| 172 |
pObj=pPage->RemoveObject(0); |
| 173 |
// these need to die before the associated SdrModel |
| 174 |
pObj.clear(); |
| 175 |
pPage.clear(); |
| 176 |
|
| 177 |
return aGraph; |
| 178 |
} |
| 179 |
|
| 180 |
FontList* ViewElementListProvider::getFontList() const |
| 181 |
{ |
| 182 |
//was old chart: |
| 183 |
//SvxFontListItem* SfxObjectShell::.GetItem(SID_ATTR_CHAR_FONTLIST) |
| 184 |
|
| 185 |
if(!m_pFontList) |
| 186 |
{ |
| 187 |
OutputDevice* pRefDev = m_pDrawModelWrapper ? m_pDrawModelWrapper->getReferenceDevice() : nullptr; |
| 188 |
OutputDevice* pDefaultOut = Application::GetDefaultDevice(); |
| 189 |
m_pFontList.reset( new FontList( pRefDev ? pRefDev : pDefaultOut |
| 190 |
, pRefDev ? pDefaultOut : nullptr) ); |
| 191 |
} |
| 192 |
return m_pFontList.get(); |
| 193 |
} |
| 194 |
} //namespace chart |
| 195 |
|
| 196 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |