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