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_sc.hxx"
26 
27 
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <com/sun/star/embed/XVisualObject.hpp>
30 #include <com/sun/star/embed/Aspects.hpp>
31 
32 
33 using namespace com::sun::star;
34 
35 // INCLUDE ---------------------------------------------------------------
36 
37 #include <unotools/moduleoptions.hxx>
38 #include <svx/svdoole2.hxx>
39 #include <svx/svdpage.hxx>
40 #include <sfx2/objsh.hxx>
41 #include <sot/storage.hxx>
42 #include <sfx2/app.hxx>
43 #include <sot/clsids.hxx>
44 #include <svx/charthelper.hxx>
45 #include "address.hxx"
46 
47 #include "scfobj.hxx"
48 #include "document.hxx"
49 #include "drwlayer.hxx"
50 #include "chartarr.hxx"
51 
52 
53 // STATIC DATA -----------------------------------------------------------
54 
55 
56 //==================================================================
57 
InsertChart(ScDocument * pDoc,SCTAB nDestTab,const Rectangle & rRect,SCTAB nSrcTab,sal_uInt16 nX1,sal_uInt16 nY1,sal_uInt16 nX2,sal_uInt16 nY2)58 void Sc10InsertObject::InsertChart( ScDocument* pDoc, SCTAB nDestTab, const Rectangle& rRect,
59 								SCTAB nSrcTab, sal_uInt16 nX1, sal_uInt16 nY1, sal_uInt16 nX2, sal_uInt16 nY2 )
60 {
61 	//	wenn Chart nicht installiert ist, darf nicht auf SCH_MOD zugegriffen werden!
62 	if ( !SvtModuleOptions().IsChart() )
63 		return;
64 
65     ::rtl::OUString aName;
66     uno::Reference < embed::XEmbeddedObject > xObj = pDoc->GetDocumentShell()->
67             GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
68     if ( xObj.is() )
69 	{
70         SdrOle2Obj* pSdrOle2Obj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aName, rRect );
71 
72 		ScDrawLayer* pModel = pDoc->GetDrawLayer();
73 		if (!pModel)
74 		{
75 			pDoc->InitDrawLayer();
76 			pModel = pDoc->GetDrawLayer();
77 			DBG_ASSERT(pModel,"Draw Layer ?");
78 		}
79 
80 		SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nDestTab));
81 		DBG_ASSERT(pPage,"Page ?");
82 		pPage->InsertObject(pSdrOle2Obj);
83 
84 		pSdrOle2Obj->SetLogicRect(rRect);				// erst nach InsertObject !!!
85         awt::Size aSz;
86         aSz.Width = rRect.GetSize().Width();
87         aSz.Height = rRect.GetSize().Height();
88         xObj->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT, aSz );
89 
90         // #121334# This call will change the chart's default background fill from white to transparent.
91         // Add here again if this is wanted (see task description for details)
92         // ChartHelper::AdaptDefaultsForChart( xObj );
93 
94 			// hier kann das Chart noch nicht mit Daten gefuettert werden,
95 			// weil die Formeln noch nicht berechnet sind.
96 			// Deshalb in die ChartCollection, die Daten werden dann im
97 			// Sc10Import dtor geholt.
98 
99 		ScChartCollection* pColl = pDoc->GetChartCollection();
100 		pColl->Insert( new ScChartArray( pDoc, nSrcTab, static_cast<SCCOL>(nX1), static_cast<SCROW>(nY1), static_cast<SCCOL>(nX2), static_cast<SCROW>(nY2), aName ) );
101 	}
102 }
103 
104 
105 
106