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