xref: /AOO41X/main/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_chart2.hxx"
30*cdf0e10cSrcweir #include "ViewElementListProvider.hxx"
31*cdf0e10cSrcweir #include "chartview/DrawModelWrapper.hxx"
32*cdf0e10cSrcweir #include "chartview/DataPointSymbolSupplier.hxx"
33*cdf0e10cSrcweir #include "macros.hxx"
34*cdf0e10cSrcweir #include "DrawViewWrapper.hxx"
35*cdf0e10cSrcweir #include <svx/xtable.hxx>
36*cdf0e10cSrcweir #include <svx/XPropertyTable.hxx>
37*cdf0e10cSrcweir #include <svx/unofill.hxx>
38*cdf0e10cSrcweir #include <svx/unoapi.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir // header for class NameOrIndex
41*cdf0e10cSrcweir #include <svx/xit.hxx>
42*cdf0e10cSrcweir // header for class XFillBitmapItem
43*cdf0e10cSrcweir #include <svx/xbtmpit.hxx>
44*cdf0e10cSrcweir #include <svx/xflftrit.hxx>
45*cdf0e10cSrcweir #include <svx/xlndsit.hxx>
46*cdf0e10cSrcweir #include <svx/xflhtit.hxx>
47*cdf0e10cSrcweir #include <svx/xflgrit.hxx>
48*cdf0e10cSrcweir // header for class XLineStartItem
49*cdf0e10cSrcweir #include <svx/xlnstit.hxx>
50*cdf0e10cSrcweir // header for class XLineEndItem
51*cdf0e10cSrcweir #include <svx/xlnedit.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //------------
54*cdf0e10cSrcweir //oldChartModelWrapper
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // header for class SfxItemPool
57*cdf0e10cSrcweir #include <svl/itempool.hxx>
58*cdf0e10cSrcweir // header for class FontList
59*cdf0e10cSrcweir #include <svtools/ctrltool.hxx>
60*cdf0e10cSrcweir // header for class Application
61*cdf0e10cSrcweir #include <vcl/svapp.hxx>
62*cdf0e10cSrcweir //------------
63*cdf0e10cSrcweir // header for class SdrObject
64*cdf0e10cSrcweir #include <svx/svdobj.hxx>
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //---------------
68*cdf0e10cSrcweir //for creation of a symbol Graphic
69*cdf0e10cSrcweir // header for class VirtualDevice
70*cdf0e10cSrcweir #include <vcl/virdev.hxx>
71*cdf0e10cSrcweir // header for class SdrView
72*cdf0e10cSrcweir #include <svx/svdview.hxx>
73*cdf0e10cSrcweir //---------------
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir //.............................................................................
76*cdf0e10cSrcweir namespace chart
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir //.............................................................................
79*cdf0e10cSrcweir using namespace ::com::sun::star;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir ViewElementListProvider::ViewElementListProvider( DrawModelWrapper* pDrawModelWrapper )
82*cdf0e10cSrcweir                         : m_pDrawModelWrapper( pDrawModelWrapper )
83*cdf0e10cSrcweir                         , m_pFontList(NULL)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir ViewElementListProvider::~ViewElementListProvider()
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir     if(m_pFontList)
90*cdf0e10cSrcweir         delete m_pFontList;
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir //-----------------------------------------------------------------------------
94*cdf0e10cSrcweir //-----------------------------------------------------------------------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir XColorTable*   ViewElementListProvider::GetColorTable() const
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
99*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetColorTable();
100*cdf0e10cSrcweir     return NULL;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir XDashList*     ViewElementListProvider::GetDashList() const
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
105*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetDashList();
106*cdf0e10cSrcweir     return NULL;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir XLineEndList*  ViewElementListProvider::GetLineEndList() const
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
111*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetLineEndList();
112*cdf0e10cSrcweir     return NULL;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir XGradientList* ViewElementListProvider::GetGradientList() const
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
117*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetGradientList();
118*cdf0e10cSrcweir     return NULL;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir XHatchList*    ViewElementListProvider::GetHatchList() const
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
123*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetHatchList();
124*cdf0e10cSrcweir     return NULL;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir XBitmapList*   ViewElementListProvider::GetBitmapList() const
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     if(m_pDrawModelWrapper)
129*cdf0e10cSrcweir         return m_pDrawModelWrapper->GetBitmapList();
130*cdf0e10cSrcweir     return NULL;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //-----------------------------------------------------------------------------
134*cdf0e10cSrcweir //-----------------------------------------------------------------------------
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir //create chartspecific symbols for linecharts
137*cdf0e10cSrcweir SdrObjList* ViewElementListProvider::GetSymbolList() const
138*cdf0e10cSrcweir {
139*cdf0e10cSrcweir     SdrObjList* m_pSymbolList = NULL;
140*cdf0e10cSrcweir     uno::Reference< drawing::XShapes > m_xSymbols(NULL);//@todo this keeps the first drawinglayer alive ...
141*cdf0e10cSrcweir     try
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         if(!m_pSymbolList || !m_pSymbolList->GetObjCount())
144*cdf0e10cSrcweir         {
145*cdf0e10cSrcweir             //@todo use mutex
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir             //get shape factory
148*cdf0e10cSrcweir 	        uno::Reference< lang::XMultiServiceFactory > xShapeFactory( m_pDrawModelWrapper->getShapeFactory() );
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir             //get hidden draw page (target):
151*cdf0e10cSrcweir 	        uno::Reference<drawing::XShapes> xTarget( m_pDrawModelWrapper->getHiddenDrawPage(), uno::UNO_QUERY );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir             //create symbols via uno and convert to native sdr objects
154*cdf0e10cSrcweir             drawing::Direction3D aSymbolSize(220,220,0); // should be 250, but 250 -> 280 ??
155*cdf0e10cSrcweir             m_xSymbols =  DataPointSymbolSupplier::create2DSymbolList( xShapeFactory, xTarget, aSymbolSize );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             SdrObject* pSdrObject = DrawViewWrapper::getSdrObject( uno::Reference< drawing::XShape >( m_xSymbols, uno::UNO_QUERY ) );
158*cdf0e10cSrcweir             if(pSdrObject)
159*cdf0e10cSrcweir                 m_pSymbolList = pSdrObject->GetSubList();
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir     catch( uno::Exception& e )
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         ASSERT_EXCEPTION( e );
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir     return m_pSymbolList;
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, const SfxItemSet* pSymbolShapeProperties ) const
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     SdrObjList* pSymbolList = this->GetSymbolList();
172*cdf0e10cSrcweir     if( !pSymbolList->GetObjCount() )
173*cdf0e10cSrcweir         return Graphic();
174*cdf0e10cSrcweir     if(nStandardSymbol<0)
175*cdf0e10cSrcweir         nStandardSymbol*=-1;
176*cdf0e10cSrcweir     if( nStandardSymbol >= static_cast<sal_Int32>(pSymbolList->GetObjCount()) )
177*cdf0e10cSrcweir         nStandardSymbol %= pSymbolList->GetObjCount();
178*cdf0e10cSrcweir     SdrObject* pObj = pSymbolList->GetObj(nStandardSymbol);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 	VirtualDevice aVDev;
181*cdf0e10cSrcweir 	aVDev.SetMapMode(MapMode(MAP_100TH_MM));
182*cdf0e10cSrcweir 	SdrModel* pModel = new SdrModel();
183*cdf0e10cSrcweir 	pModel->GetItemPool().FreezeIdRanges();
184*cdf0e10cSrcweir 	SdrPage* pPage = new SdrPage( *pModel, sal_False );
185*cdf0e10cSrcweir 	pPage->SetSize(Size(1000,1000));
186*cdf0e10cSrcweir 	pModel->InsertPage( pPage, 0 );
187*cdf0e10cSrcweir 	SdrView* pView = new SdrView( pModel, &aVDev );
188*cdf0e10cSrcweir 	pView->hideMarkHandles();
189*cdf0e10cSrcweir 	SdrPageView* pPageView = pView->ShowSdrPage(pPage);
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     pObj=pObj->Clone();
192*cdf0e10cSrcweir 	pPage->NbcInsertObject(pObj);
193*cdf0e10cSrcweir 	pView->MarkObj(pObj,pPageView);
194*cdf0e10cSrcweir     if( pSymbolShapeProperties )
195*cdf0e10cSrcweir         pObj->SetMergedItemSet(*pSymbolShapeProperties);
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	GDIMetaFile aMeta(pView->GetAllMarkedMetaFile());
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	Graphic aGraph(aMeta);
200*cdf0e10cSrcweir     Size aSize = pObj->GetSnapRect().GetSize();
201*cdf0e10cSrcweir 	aGraph.SetPrefSize(aSize);
202*cdf0e10cSrcweir 	aGraph.SetPrefMapMode(MAP_100TH_MM);
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	pView->UnmarkAll();
205*cdf0e10cSrcweir 	pObj=pPage->RemoveObject(0);
206*cdf0e10cSrcweir     SdrObject::Free( pObj );
207*cdf0e10cSrcweir 	delete pView;
208*cdf0e10cSrcweir 	delete pModel;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	return aGraph;
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir //-----------------------------------------------------------------------------
214*cdf0e10cSrcweir //-----------------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir FontList* ViewElementListProvider::getFontList() const
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     //was old chart:
219*cdf0e10cSrcweir     //SvxFontListItem* SfxObjectShell::.GetItem(SID_ATTR_CHAR_FONTLIST)
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     if(!m_pFontList)
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir         OutputDevice* pRefDev    = m_pDrawModelWrapper ? m_pDrawModelWrapper->getReferenceDevice() : NULL;
224*cdf0e10cSrcweir         OutputDevice* pDefaultOut = Application::GetDefaultDevice();	// #67730#
225*cdf0e10cSrcweir         m_pFontList = new FontList( pRefDev ? pRefDev    : pDefaultOut
226*cdf0e10cSrcweir                                 , pRefDev ? pDefaultOut : NULL
227*cdf0e10cSrcweir                                 , sal_False );
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir     return m_pFontList;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir /*
233*cdf0e10cSrcweir SfxPrinter* ObjectPropertiesDialogParameter::getPrinter()
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     //was old chart:
236*cdf0e10cSrcweir     //SfxPrinter* SchChartDocShell::GetPrinter()
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     // OLE-Objekt: kein Printer anlegen ??? see old chart: :UpdateTablePointers
239*cdf0e10cSrcweir     //@todo get printer from calc or other container
240*cdf0e10cSrcweir     //return NULL;
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir     SfxPrinter* pPrinter = NULL;
243*cdf0e10cSrcweir     bool bOwnPrinter = true;
244*cdf0e10cSrcweir 	if (!pPrinter)
245*cdf0e10cSrcweir 	{
246*cdf0e10cSrcweir 		SfxBoolItem aItem(SID_PRINTER_NOTFOUND_WARN, sal_True);
247*cdf0e10cSrcweir 		// ItemSet mit speziellem Poolbereich anlegen
248*cdf0e10cSrcweir 		SfxItemSet* pSet = new SfxItemSet(GetPool(),
249*cdf0e10cSrcweir 										  SID_PRINTER_NOTFOUND_WARN,
250*cdf0e10cSrcweir 										  SID_PRINTER_NOTFOUND_WARN, 0);
251*cdf0e10cSrcweir 		pSet->Put(aItem);
252*cdf0e10cSrcweir 		pPrinter = new SfxPrinter(pSet); //@todo ->need to remember and delete
253*cdf0e10cSrcweir 		bOwnPrinter = sal_True;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 		MapMode aMapMode = pPrinter->GetMapMode();
256*cdf0e10cSrcweir 		aMapMode.SetMapUnit(MAP_100TH_MM);
257*cdf0e10cSrcweir 		pPrinter->SetMapMode(aMapMode);
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 		if (pChDoc)
260*cdf0e10cSrcweir 		{
261*cdf0e10cSrcweir 			if (pPrinter != pChDoc->GetRefDevice())
262*cdf0e10cSrcweir 				pChDoc->SetRefDevice(pPrinter);
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 			if (pPrinter != pChDoc->GetOutliner()->GetRefDevice())
265*cdf0e10cSrcweir 				pChDoc->GetOutliner()->SetRefDevice(pPrinter);
266*cdf0e10cSrcweir 		}
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir 	return pPrinter;
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir */
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir //.............................................................................
273*cdf0e10cSrcweir } //namespace chart
274*cdf0e10cSrcweir //.............................................................................
275