xref: /AOO41X/main/sc/source/ui/drawfunc/fuins2.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_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir //------------------------------------------------------------------------
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
39*cdf0e10cSrcweir #include <sot/exchange.hxx>
40*cdf0e10cSrcweir #include <svl/globalnameitem.hxx>
41*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
42*cdf0e10cSrcweir #include <sfx2/docfile.hxx>
43*cdf0e10cSrcweir #include <svl/stritem.hxx>
44*cdf0e10cSrcweir #include <svx/svdoole2.hxx>
45*cdf0e10cSrcweir #include <svx/pfiledlg.hxx>
46*cdf0e10cSrcweir #include <tools/urlobj.hxx>
47*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
48*cdf0e10cSrcweir #include <svl/urihelper.hxx>
49*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
50*cdf0e10cSrcweir #include <svtools/insdlg.hxx>
51*cdf0e10cSrcweir #include <svtools/soerr.hxx>
52*cdf0e10cSrcweir #include <svx/svxdlg.hxx>
53*cdf0e10cSrcweir #include <sot/clsids.hxx>
54*cdf0e10cSrcweir #include <svx/svdpagv.hxx>
55*cdf0e10cSrcweir #include <svx/svdpage.hxx>
56*cdf0e10cSrcweir #include <svx/svdundo.hxx>
57*cdf0e10cSrcweir #include <sfx2/msgpool.hxx>
58*cdf0e10cSrcweir #include <scmod.hxx>
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // BM/IHA --
61*cdf0e10cSrcweir #include <cppuhelper/component_context.hxx>
62*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
63*cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
64*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
65*cdf0e10cSrcweir #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
66*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
67*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
68*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataProvider.hpp>
69*cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
70*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
71*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
72*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
73*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
74*cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
75*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir using namespace ::com::sun::star;
78*cdf0e10cSrcweir // BM/IHA --
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // erAck
81*cdf0e10cSrcweir #include "chart2uno.hxx"
82*cdf0e10cSrcweir // erAck
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir #include "fuinsert.hxx"
85*cdf0e10cSrcweir #include "tabvwsh.hxx"
86*cdf0e10cSrcweir #include "sc.hrc"
87*cdf0e10cSrcweir #include "chartarr.hxx"
88*cdf0e10cSrcweir #include "docsh.hxx"
89*cdf0e10cSrcweir #include "document.hxx"
90*cdf0e10cSrcweir #include "undotab.hxx"
91*cdf0e10cSrcweir #include "chartlis.hxx"
92*cdf0e10cSrcweir #include "uiitems.hxx"
93*cdf0e10cSrcweir #include "globstr.hrc"
94*cdf0e10cSrcweir #include "drawview.hxx"
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir extern SdrObject* pSkipPaintObj;			// output.cxx - dieses Objekt nicht zeichnen
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir //------------------------------------------------------------------------
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir #define IS_AVAILABLE(WhichId,ppItem) \
101*cdf0e10cSrcweir     (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData,
104*cdf0e10cSrcweir                     const rtl::OUString& rRangeParam )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir     ScDocShell* pDocShell = pViewData->GetDocShell();
107*cdf0e10cSrcweir     ScDocument* pScDoc = pDocShell->GetDocument();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     rtl::OUString aRangeString( rRangeParam );
110*cdf0e10cSrcweir     if ( !aRangeString.getLength() )
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir         SCCOL nCol1 = 0;
113*cdf0e10cSrcweir         SCROW nRow1 = 0;
114*cdf0e10cSrcweir         SCTAB nTab1 = 0;
115*cdf0e10cSrcweir         SCCOL nCol2 = 0;
116*cdf0e10cSrcweir         SCROW nRow2 = 0;
117*cdf0e10cSrcweir         SCTAB nTab2 = 0;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         ScMarkData& rMark = pViewData->GetMarkData();
120*cdf0e10cSrcweir         if ( !rMark.IsMarked() )
121*cdf0e10cSrcweir             pViewData->GetView()->MarkDataArea( sal_True );
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir         if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
124*cdf0e10cSrcweir         {
125*cdf0e10cSrcweir             PutInOrder( nCol1, nCol2 );
126*cdf0e10cSrcweir             PutInOrder( nRow1, nRow2 );
127*cdf0e10cSrcweir             if ( nCol2>nCol1 || nRow2>nRow1 )
128*cdf0e10cSrcweir             {
129*cdf0e10cSrcweir                 ScDocument* pDoc = pViewData->GetDocument();
130*cdf0e10cSrcweir                 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir                 String aStr;
133*cdf0e10cSrcweir                 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
134*cdf0e10cSrcweir                 aRange.Format( aStr, SCR_ABS_3D, pScDoc );
135*cdf0e10cSrcweir                 aRangeString = aStr;
136*cdf0e10cSrcweir             }
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     if ( aRangeString.getLength() )
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         // connect to Calc data (if no range string, leave chart alone, with its own data)
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir         uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
145*cdf0e10cSrcweir         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
146*cdf0e10cSrcweir         if( xCompSupp.is())
147*cdf0e10cSrcweir             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
148*cdf0e10cSrcweir         OSL_ASSERT( xReceiver.is());
149*cdf0e10cSrcweir         if( xReceiver.is() )
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir             uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( pScDoc );
152*cdf0e10cSrcweir             xReceiver->attachDataProvider( xDataProvider );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir             uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
155*cdf0e10cSrcweir             xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             // Same behavior as with old chart: Always assume data series in columns
158*cdf0e10cSrcweir             chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
159*cdf0e10cSrcweir             bool bHasCategories = false;
160*cdf0e10cSrcweir             bool bFirstCellAsLabel = false;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir             // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
163*cdf0e10cSrcweir             ScRangeListRef aRangeListRef( new ScRangeList );
164*cdf0e10cSrcweir             aRangeListRef->Parse( aRangeString, pScDoc );
165*cdf0e10cSrcweir             if ( aRangeListRef->Count() )
166*cdf0e10cSrcweir             {
167*cdf0e10cSrcweir                 pScDoc->LimitChartIfAll( aRangeListRef );               // limit whole columns/rows to used area
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir                 // update string from modified ranges.  The ranges must be in the current formula syntax.
170*cdf0e10cSrcweir                 String aTmpStr;
171*cdf0e10cSrcweir                 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, pScDoc, pScDoc->GetAddressConvention() );
172*cdf0e10cSrcweir                 aRangeString = aTmpStr;
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir                 ScChartPositioner aChartPositioner( pScDoc, aRangeListRef );
175*cdf0e10cSrcweir                 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
176*cdf0e10cSrcweir                 if( pPositionMap )
177*cdf0e10cSrcweir                 {
178*cdf0e10cSrcweir                     SCSIZE nRowCount = pPositionMap->GetRowCount();
179*cdf0e10cSrcweir                     if( 1==nRowCount )
180*cdf0e10cSrcweir                         eDataRowSource = chart::ChartDataRowSource_ROWS;
181*cdf0e10cSrcweir                 }
182*cdf0e10cSrcweir                 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
183*cdf0e10cSrcweir                 {
184*cdf0e10cSrcweir                     bHasCategories = aChartPositioner.HasRowHeaders();
185*cdf0e10cSrcweir                     bFirstCellAsLabel = aChartPositioner.HasColHeaders();
186*cdf0e10cSrcweir                 }
187*cdf0e10cSrcweir                 else    // in case the default is changed
188*cdf0e10cSrcweir                 {
189*cdf0e10cSrcweir                     bHasCategories = aChartPositioner.HasColHeaders();
190*cdf0e10cSrcweir                     bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
191*cdf0e10cSrcweir                 }
192*cdf0e10cSrcweir             }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir             uno::Sequence< beans::PropertyValue > aArgs( 4 );
195*cdf0e10cSrcweir             aArgs[0] = beans::PropertyValue(
196*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
197*cdf0e10cSrcweir                 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
198*cdf0e10cSrcweir             aArgs[1] = beans::PropertyValue(
199*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("HasCategories"), -1,
200*cdf0e10cSrcweir                 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
201*cdf0e10cSrcweir             aArgs[2] = beans::PropertyValue(
202*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
203*cdf0e10cSrcweir                 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
204*cdf0e10cSrcweir             aArgs[3] = beans::PropertyValue(
205*cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii("DataRowSource"), -1,
206*cdf0e10cSrcweir                 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
207*cdf0e10cSrcweir             xReceiver->setArguments( aArgs );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir             // don't create chart listener here (range may be modified in chart dialog)
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir     }
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir /*************************************************************************
215*cdf0e10cSrcweir |*
216*cdf0e10cSrcweir |* FuInsertOLE::Konstruktor
217*cdf0e10cSrcweir |*
218*cdf0e10cSrcweir \************************************************************************/
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
221*cdf0e10cSrcweir 		   SdrModel* pDoc, SfxRequest& rReq)
222*cdf0e10cSrcweir     : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
223*cdf0e10cSrcweir {
224*cdf0e10cSrcweir 	if( ! rReq.IsAPI() )
225*cdf0e10cSrcweir 		rReq.Done();
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 	//!	hier DLL's initalisieren, damit die Factories existieren?
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj;
230*cdf0e10cSrcweir     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
231*cdf0e10cSrcweir 	sal_Bool bIsFromFile = sal_False;
232*cdf0e10cSrcweir     ::rtl::OUString aName;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir     sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
235*cdf0e10cSrcweir     ::rtl::OUString aIconMediaType;
236*cdf0e10cSrcweir     uno::Reference< io::XInputStream > xIconMetaFile;
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	sal_uInt16 nSlot = rReq.GetSlot();
240*cdf0e10cSrcweir     SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
241*cdf0e10cSrcweir     if ( nSlot == SID_INSERT_OBJECT && pNameItem )
242*cdf0e10cSrcweir 	{
243*cdf0e10cSrcweir         SvGlobalName aClassName = pNameItem->GetValue();
244*cdf0e10cSrcweir         xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir     else if ( nSlot == SID_INSERT_SMATH )
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         if ( SvtModuleOptions().IsMath() )
249*cdf0e10cSrcweir         {
250*cdf0e10cSrcweir             nSlot = SID_INSERT_OBJECT;
251*cdf0e10cSrcweir             xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName );
252*cdf0e10cSrcweir             rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
253*cdf0e10cSrcweir         }
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir     else
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         SvObjectServerList aServerLst;
258*cdf0e10cSrcweir         switch ( nSlot )
259*cdf0e10cSrcweir         {
260*cdf0e10cSrcweir             case SID_INSERT_OBJECT :
261*cdf0e10cSrcweir                 aServerLst.FillInsertObjects();
262*cdf0e10cSrcweir                 aServerLst.Remove( ScDocShell::Factory().GetClassId() );   // Starcalc nicht anzeigen
263*cdf0e10cSrcweir                 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
264*cdf0e10cSrcweir             case SID_INSERT_PLUGIN :
265*cdf0e10cSrcweir             case SID_INSERT_FLOATINGFRAME :
266*cdf0e10cSrcweir             {
267*cdf0e10cSrcweir                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
268*cdf0e10cSrcweir                 SfxAbstractInsertObjectDialog* pDlg =
269*cdf0e10cSrcweir                         pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
270*cdf0e10cSrcweir                         xStorage, &aServerLst );
271*cdf0e10cSrcweir                 if ( pDlg )
272*cdf0e10cSrcweir                 {
273*cdf0e10cSrcweir                     pDlg->Execute();
274*cdf0e10cSrcweir                     xObj = pDlg->GetObject();
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 					xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
277*cdf0e10cSrcweir 					if ( xIconMetaFile.is() )
278*cdf0e10cSrcweir 						nAspect = embed::Aspects::MSOLE_ICON;
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir                     if ( xObj.is() )
281*cdf0e10cSrcweir                         pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
282*cdf0e10cSrcweir                     // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
283*cdf0e10cSrcweir                     bIsFromFile = !pDlg->IsCreateNew();
284*cdf0e10cSrcweir                     DELETEZ( pDlg );
285*cdf0e10cSrcweir                 }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir                 break;
288*cdf0e10cSrcweir             }
289*cdf0e10cSrcweir             case SID_INSERT_SOUND :
290*cdf0e10cSrcweir             case SID_INSERT_VIDEO :
291*cdf0e10cSrcweir             {
292*cdf0e10cSrcweir                 // create special filedialog for plugins
293*cdf0e10cSrcweir                 SvxPluginFileDlg aPluginFileDialog(pWin, nSlot);
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir                 // open filedlg
296*cdf0e10cSrcweir                 if ( ERRCODE_NONE == aPluginFileDialog.Execute() )
297*cdf0e10cSrcweir                 {
298*cdf0e10cSrcweir                     // get URL
299*cdf0e10cSrcweir                     INetURLObject aURL;
300*cdf0e10cSrcweir                     aURL.SetSmartProtocol( INET_PROT_FILE );
301*cdf0e10cSrcweir                     if ( aURL.SetURL( aPluginFileDialog.GetPath() ) )
302*cdf0e10cSrcweir                     {
303*cdf0e10cSrcweir                         // create a plugin object
304*cdf0e10cSrcweir                         ::rtl::OUString aObjName;
305*cdf0e10cSrcweir                         SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
306*cdf0e10cSrcweir                         comphelper::EmbeddedObjectContainer aCnt( xStorage );
307*cdf0e10cSrcweir                         xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aObjName );
308*cdf0e10cSrcweir                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
309*cdf0e10cSrcweir                         {
310*cdf0e10cSrcweir                             // set properties from dialog
311*cdf0e10cSrcweir                             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
312*cdf0e10cSrcweir                             if ( xSet.is() )
313*cdf0e10cSrcweir                             {
314*cdf0e10cSrcweir                                 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
315*cdf0e10cSrcweir                                         uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
316*cdf0e10cSrcweir                             }
317*cdf0e10cSrcweir                         }
318*cdf0e10cSrcweir                     }
319*cdf0e10cSrcweir                     else
320*cdf0e10cSrcweir                     {
321*cdf0e10cSrcweir                         DBG_ERROR("Invalid URL!");
322*cdf0e10cSrcweir                         //! error message
323*cdf0e10cSrcweir                         //! can this happen???
324*cdf0e10cSrcweir                     }
325*cdf0e10cSrcweir                 }
326*cdf0e10cSrcweir             }
327*cdf0e10cSrcweir         }
328*cdf0e10cSrcweir     }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 	//	SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
331*cdf0e10cSrcweir     if (xObj.is())
332*cdf0e10cSrcweir 	{
333*cdf0e10cSrcweir 		pView->UnmarkAll();
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 		try
336*cdf0e10cSrcweir 		{
337*cdf0e10cSrcweir 			::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
338*cdf0e10cSrcweir 			Size aSize;
339*cdf0e10cSrcweir 			MapMode aMap100( MAP_100TH_MM );
340*cdf0e10cSrcweir 			MapUnit aMapUnit = MAP_100TH_MM;
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 			if ( nAspect == embed::Aspects::MSOLE_ICON )
343*cdf0e10cSrcweir 			{
344*cdf0e10cSrcweir 				aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
345*cdf0e10cSrcweir 				aSize = aObjRef.GetSize( &aMap100 );
346*cdf0e10cSrcweir 			}
347*cdf0e10cSrcweir 			else
348*cdf0e10cSrcweir 			{
349*cdf0e10cSrcweir             	awt::Size aSz;
350*cdf0e10cSrcweir 				try
351*cdf0e10cSrcweir 				{
352*cdf0e10cSrcweir 					aSz = xObj->getVisualAreaSize( nAspect );
353*cdf0e10cSrcweir 				}
354*cdf0e10cSrcweir 				catch( embed::NoVisualAreaSizeException& )
355*cdf0e10cSrcweir 				{
356*cdf0e10cSrcweir 					// the default size will be set later
357*cdf0e10cSrcweir 				}
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir             	aSize = Size( aSz.Width, aSz.Height );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir             	aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
362*cdf0e10cSrcweir             	if (aSize.Height() == 0 || aSize.Width() == 0)
363*cdf0e10cSrcweir             	{
364*cdf0e10cSrcweir                 	// Rechteck mit ausgewogenem Kantenverhaeltnis
365*cdf0e10cSrcweir 					aSize.Width() = 5000;
366*cdf0e10cSrcweir 					aSize.Height() = 5000;
367*cdf0e10cSrcweir                 	Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
368*cdf0e10cSrcweir                 	aSz.Width = aTmp.Width();
369*cdf0e10cSrcweir                 	aSz.Height = aTmp.Height();
370*cdf0e10cSrcweir                 	xObj->setVisualAreaSize( nAspect, aSz );
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir                 	//  re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
373*cdf0e10cSrcweir                 	aSize = Window::LogicToLogic( aTmp,
374*cdf0e10cSrcweir                                 	MapMode( aMapUnit ), aMap100 );
375*cdf0e10cSrcweir 				}
376*cdf0e10cSrcweir 				else
377*cdf0e10cSrcweir 					aSize = Window::LogicToLogic( aSize,
378*cdf0e10cSrcweir                                 	MapMode( aMapUnit ), aMap100 );
379*cdf0e10cSrcweir 			}
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 			//	Chart initialisieren ?
382*cdf0e10cSrcweir             if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
383*cdf0e10cSrcweir                 lcl_ChartInit( xObj, pViewSh->GetViewData(), rtl::OUString() );
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir 			ScViewData* pData = pViewSh->GetViewData();
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 			Point aPnt = pViewSh->GetInsertPos();
388*cdf0e10cSrcweir 			if ( pData->GetDocument()->IsNegativePage( pData->GetTabNo() ) )
389*cdf0e10cSrcweir 				aPnt.X() -= aSize.Width();		// move position to left edge
390*cdf0e10cSrcweir 			Rectangle aRect (aPnt, aSize);
391*cdf0e10cSrcweir             SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 				// Dieses Objekt nicht vor dem Aktivieren zeichnen
394*cdf0e10cSrcweir 				// (in MarkListHasChanged kommt ein Update)
395*cdf0e10cSrcweir 			if (!bIsFromFile)
396*cdf0e10cSrcweir 				pSkipPaintObj = pObj;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 			SdrPageView* pPV = pView->GetSdrPageView();
399*cdf0e10cSrcweir 			pView->InsertObjectAtView(pObj, *pPV);
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 			if ( nAspect != embed::Aspects::MSOLE_ICON )
402*cdf0e10cSrcweir 			{
403*cdf0e10cSrcweir 				//	#73279# Math objects change their object size during InsertObject.
404*cdf0e10cSrcweir 				//	New size must be set in SdrObject, or a wrong scale will be set at
405*cdf0e10cSrcweir 				//	ActivateObject.
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 				try
408*cdf0e10cSrcweir 				{
409*cdf0e10cSrcweir             		awt::Size aSz = xObj->getVisualAreaSize( nAspect );
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir             		Size aNewSize( aSz.Width, aSz.Height );
412*cdf0e10cSrcweir             		aNewSize = OutputDevice::LogicToLogic( aNewSize, aMapUnit, MAP_100TH_MM );
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir             		if ( aNewSize != aSize )
415*cdf0e10cSrcweir 					{
416*cdf0e10cSrcweir 						aRect.SetSize( aNewSize );
417*cdf0e10cSrcweir 						pObj->SetLogicRect( aRect );
418*cdf0e10cSrcweir 					}
419*cdf0e10cSrcweir 				}
420*cdf0e10cSrcweir 				catch( embed::NoVisualAreaSizeException& )
421*cdf0e10cSrcweir 				{}
422*cdf0e10cSrcweir 			}
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 			if ( !rReq.IsAPI() )
425*cdf0e10cSrcweir 			{
426*cdf0e10cSrcweir 				// XXX Activate aus Makro ist toedlich !!! ???
427*cdf0e10cSrcweir 				if (bIsFromFile)
428*cdf0e10cSrcweir 				{
429*cdf0e10cSrcweir 					// #45012# Objekt ist selektiert, also Draw-Shell aktivieren
430*cdf0e10cSrcweir 					pViewShell->SetDrawShell( sal_True );
431*cdf0e10cSrcweir 				}
432*cdf0e10cSrcweir 				else
433*cdf0e10cSrcweir 				{
434*cdf0e10cSrcweir 					pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
435*cdf0e10cSrcweir 					pSkipPaintObj = NULL;
436*cdf0e10cSrcweir 				}
437*cdf0e10cSrcweir 			}
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir 			rReq.Done();
440*cdf0e10cSrcweir 		}
441*cdf0e10cSrcweir 		catch( uno::Exception& )
442*cdf0e10cSrcweir 		{
443*cdf0e10cSrcweir 			OSL_ASSERT( "May need error handling here!\n" );
444*cdf0e10cSrcweir 		}
445*cdf0e10cSrcweir 	}
446*cdf0e10cSrcweir 	else
447*cdf0e10cSrcweir 		rReq.Ignore();
448*cdf0e10cSrcweir }
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir /*************************************************************************
451*cdf0e10cSrcweir |*
452*cdf0e10cSrcweir |* FuInsertOLE::Destruktor
453*cdf0e10cSrcweir |*
454*cdf0e10cSrcweir \************************************************************************/
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir FuInsertOLE::~FuInsertOLE()
457*cdf0e10cSrcweir {
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir /*************************************************************************
461*cdf0e10cSrcweir |*
462*cdf0e10cSrcweir |* FuInsertOLE::Function aktivieren
463*cdf0e10cSrcweir |*
464*cdf0e10cSrcweir \************************************************************************/
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir void FuInsertOLE::Activate()
467*cdf0e10cSrcweir {
468*cdf0e10cSrcweir 	FuPoor::Activate();
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir /*************************************************************************
472*cdf0e10cSrcweir |*
473*cdf0e10cSrcweir |* FuInsertOLE::Function deaktivieren
474*cdf0e10cSrcweir |*
475*cdf0e10cSrcweir \************************************************************************/
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir void FuInsertOLE::Deactivate()
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir 	FuPoor::Deactivate();
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir /*************************************************************************
483*cdf0e10cSrcweir |*
484*cdf0e10cSrcweir |* FuInsertChart::Konstruktor
485*cdf0e10cSrcweir |*
486*cdf0e10cSrcweir \************************************************************************/
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
489*cdf0e10cSrcweir 		   SdrModel* pDoc, SfxRequest& rReq)
490*cdf0e10cSrcweir     : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
491*cdf0e10cSrcweir {
492*cdf0e10cSrcweir 	const SfxItemSet*	pReqArgs	= rReq.GetArgs();
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir 	if( ! rReq.IsAPI() )
495*cdf0e10cSrcweir 		rReq.Done();
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir     if( SvtModuleOptions().IsChart() )
498*cdf0e10cSrcweir     {
499*cdf0e10cSrcweir         // ----------------------------------------
500*cdf0e10cSrcweir         // BM/IHA --
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir         // get range
503*cdf0e10cSrcweir         ::rtl::OUString aRangeString;
504*cdf0e10cSrcweir         ScRange aPositionRange;             // cell range for chart positioning
505*cdf0e10cSrcweir         if( pReqArgs )
506*cdf0e10cSrcweir         {
507*cdf0e10cSrcweir             const SfxPoolItem* pItem;
508*cdf0e10cSrcweir             if( IS_AVAILABLE( FN_PARAM_5, &pItem ) )
509*cdf0e10cSrcweir             aRangeString = ::rtl::OUString( ((const SfxStringItem*)pItem)->GetValue());
510*cdf0e10cSrcweir 
511*cdf0e10cSrcweir             aPositionRange = pViewSh->GetViewData()->GetCurPos();
512*cdf0e10cSrcweir         }
513*cdf0e10cSrcweir         else
514*cdf0e10cSrcweir         {
515*cdf0e10cSrcweir             ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData();
516*cdf0e10cSrcweir             bool bAutomaticMark = false;
517*cdf0e10cSrcweir             if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
518*cdf0e10cSrcweir             {
519*cdf0e10cSrcweir 		        pViewSh->GetViewData()->GetView()->MarkDataArea( sal_True );
520*cdf0e10cSrcweir                 bAutomaticMark = true;
521*cdf0e10cSrcweir             }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir             ScMarkData aMultiMark( rMark );
524*cdf0e10cSrcweir             aMultiMark.MarkToMulti();
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir             ScRangeList aRanges;
527*cdf0e10cSrcweir             aMultiMark.FillRangeListWithMarks( &aRanges, sal_False );
528*cdf0e10cSrcweir             String aStr;
529*cdf0e10cSrcweir             ScDocument* pDocument = pViewSh->GetViewData()->GetDocument();
530*cdf0e10cSrcweir             aRanges.Format( aStr, SCR_ABS_3D, pDocument, pDocument->GetAddressConvention() );
531*cdf0e10cSrcweir             aRangeString = aStr;
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir             // get "total" range for positioning
534*cdf0e10cSrcweir             sal_uLong nCount = aRanges.Count();
535*cdf0e10cSrcweir             if ( nCount > 0 )
536*cdf0e10cSrcweir             {
537*cdf0e10cSrcweir                 aPositionRange = *aRanges.GetObject(0);
538*cdf0e10cSrcweir                 for (sal_uLong i=1; i<nCount; i++)
539*cdf0e10cSrcweir                     aPositionRange.ExtendTo( *aRanges.GetObject(i) );
540*cdf0e10cSrcweir             }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir             if(bAutomaticMark)
543*cdf0e10cSrcweir                 pViewSh->GetViewData()->GetView()->Unmark();
544*cdf0e10cSrcweir         }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir         // ----------------------------------------
547*cdf0e10cSrcweir         // adapted old code
548*cdf0e10cSrcweir         pView->UnmarkAll();
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir         ::rtl::OUString aName;
551*cdf0e10cSrcweir         const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir         uno::Reference < embed::XEmbeddedObject > xObj =
554*cdf0e10cSrcweir             pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName );
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir         uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
557*cdf0e10cSrcweir         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
558*cdf0e10cSrcweir         if( xCompSupp.is())
559*cdf0e10cSrcweir             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir         // lock the model to suppress any internal updates
562*cdf0e10cSrcweir         uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
563*cdf0e10cSrcweir         if( xChartModel.is() )
564*cdf0e10cSrcweir             xChartModel->lockControllers();
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir         ScRangeListRef aDummy;
567*cdf0e10cSrcweir         Rectangle aMarkDest;
568*cdf0e10cSrcweir         SCTAB nMarkTab;
569*cdf0e10cSrcweir         sal_Bool bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab );
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir         //	Objekt-Groesse
572*cdf0e10cSrcweir         awt::Size aSz = xObj->getVisualAreaSize( nAspect );
573*cdf0e10cSrcweir         Size aSize( aSz.Width, aSz.Height );
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir         MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir         sal_Bool bSizeCh = sal_False;
578*cdf0e10cSrcweir         if (bDrawRect && !aMarkDest.IsEmpty())
579*cdf0e10cSrcweir         {
580*cdf0e10cSrcweir             aSize = aMarkDest.GetSize();
581*cdf0e10cSrcweir             bSizeCh = sal_True;
582*cdf0e10cSrcweir         }
583*cdf0e10cSrcweir         if (aSize.Height() <= 0 || aSize.Width() <= 0)
584*cdf0e10cSrcweir         {
585*cdf0e10cSrcweir             aSize.Width() = 5000;
586*cdf0e10cSrcweir             aSize.Height() = 5000;
587*cdf0e10cSrcweir             bSizeCh = sal_True;
588*cdf0e10cSrcweir         }
589*cdf0e10cSrcweir         if (bSizeCh)
590*cdf0e10cSrcweir         {
591*cdf0e10cSrcweir             aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
592*cdf0e10cSrcweir             aSz.Width = aSize.Width();
593*cdf0e10cSrcweir             aSz.Height = aSize.Height();
594*cdf0e10cSrcweir             xObj->setVisualAreaSize( nAspect, aSz );
595*cdf0e10cSrcweir         }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir         ScViewData* pData = pViewSh->GetViewData();
598*cdf0e10cSrcweir         ScDocShell* pScDocSh = pData->GetDocShell();
599*cdf0e10cSrcweir         ScDocument* pScDoc	 = pScDocSh->GetDocument();
600*cdf0e10cSrcweir         sal_Bool bUndo (pScDoc->IsUndoEnabled());
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir         if( pReqArgs )
603*cdf0e10cSrcweir         {
604*cdf0e10cSrcweir             const SfxPoolItem* pItem;
605*cdf0e10cSrcweir             sal_uInt16 nToTable = 0;
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir             if( IS_AVAILABLE( FN_PARAM_4, &pItem ) )
608*cdf0e10cSrcweir             {
609*cdf0e10cSrcweir                 if ( pItem->ISA( SfxUInt16Item ) )
610*cdf0e10cSrcweir                     nToTable = ((const SfxUInt16Item*)pItem)->GetValue();
611*cdf0e10cSrcweir                 else if ( pItem->ISA( SfxBoolItem ) )
612*cdf0e10cSrcweir                 {
613*cdf0e10cSrcweir                     //	#46033# in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
614*cdf0e10cSrcweir                     //	-> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir                     if ( ((const SfxBoolItem*)pItem)->GetValue() )
617*cdf0e10cSrcweir                         nToTable = static_cast<sal_uInt16>(pScDoc->GetTableCount());
618*cdf0e10cSrcweir                     else
619*cdf0e10cSrcweir                         nToTable = static_cast<sal_uInt16>(pData->GetTabNo());
620*cdf0e10cSrcweir                 }
621*cdf0e10cSrcweir             }
622*cdf0e10cSrcweir             else
623*cdf0e10cSrcweir             {
624*cdf0e10cSrcweir                 if (bDrawRect)
625*cdf0e10cSrcweir                     nToTable = static_cast<sal_uInt16>(nMarkTab);
626*cdf0e10cSrcweir                 rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
627*cdf0e10cSrcweir             }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir             // auf neue Tabelle ausgeben?
630*cdf0e10cSrcweir             if ( nToTable == pScDoc->GetTableCount() )
631*cdf0e10cSrcweir             {
632*cdf0e10cSrcweir                 // dann los...
633*cdf0e10cSrcweir                 String		aTabName;
634*cdf0e10cSrcweir                 SCTAB		nNewTab = pScDoc->GetTableCount();
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir                 pScDoc->CreateValidTabName( aTabName );
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir                 if ( pScDoc->InsertTab( nNewTab, aTabName ) )
639*cdf0e10cSrcweir                 {
640*cdf0e10cSrcweir                     sal_Bool bAppend = sal_True;
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir                     if (bUndo)
643*cdf0e10cSrcweir                     {
644*cdf0e10cSrcweir                         pScDocSh->GetUndoManager()->AddUndoAction(
645*cdf0e10cSrcweir                             new ScUndoInsertTab( pScDocSh, nNewTab,
646*cdf0e10cSrcweir                                                  bAppend, aTabName ) );
647*cdf0e10cSrcweir                     }
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir                     pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
650*cdf0e10cSrcweir                     pViewSh->SetTabNo( nNewTab, sal_True );
651*cdf0e10cSrcweir                     pScDocSh->PostPaintExtras();			//! erst hinterher ???
652*cdf0e10cSrcweir                 }
653*cdf0e10cSrcweir                 else
654*cdf0e10cSrcweir                 {
655*cdf0e10cSrcweir                     DBG_ERROR( "Could not create new table :-/" );
656*cdf0e10cSrcweir                 }
657*cdf0e10cSrcweir             }
658*cdf0e10cSrcweir             else if ( nToTable != pData->GetTabNo() )
659*cdf0e10cSrcweir             {
660*cdf0e10cSrcweir                 pViewSh->SetTabNo( nToTable, sal_True );
661*cdf0e10cSrcweir             }
662*cdf0e10cSrcweir         }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir         lcl_ChartInit( xObj, pData, aRangeString );         // set source range, auto-detect column/row headers
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir         //	Objekt-Position
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir         Point aStart;
669*cdf0e10cSrcweir         if ( bDrawRect )
670*cdf0e10cSrcweir             aStart = aMarkDest.TopLeft();						// marked by hand
671*cdf0e10cSrcweir         else
672*cdf0e10cSrcweir         {
673*cdf0e10cSrcweir             // get chart position (from window size and data range)
674*cdf0e10cSrcweir             aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
675*cdf0e10cSrcweir         }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir         Rectangle aRect (aStart, aSize);
678*cdf0e10cSrcweir         SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir         // Dieses Objekt nicht vor dem Aktivieren zeichnen
681*cdf0e10cSrcweir         // (in MarkListHasChanged kommt ein Update)
682*cdf0e10cSrcweir         pSkipPaintObj = pObj;
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir         SdrPageView* pPV = pView->GetSdrPageView();
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir //        pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir         // use the page instead of the view to insert, so no undo action is created yet
689*cdf0e10cSrcweir         SdrPage* pInsPage = pPV->GetPage();
690*cdf0e10cSrcweir         pInsPage->InsertObject( pObj );
691*cdf0e10cSrcweir         pView->UnmarkAllObj();
692*cdf0e10cSrcweir         pView->MarkObj( pObj, pPV );
693*cdf0e10cSrcweir         bool bAddUndo = true;               // add undo action later, unless the dialog is canceled
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir         if (rReq.IsAPI())
696*cdf0e10cSrcweir         {
697*cdf0e10cSrcweir             if( xChartModel.is() )
698*cdf0e10cSrcweir                 xChartModel->unlockControllers();
699*cdf0e10cSrcweir         }
700*cdf0e10cSrcweir         else
701*cdf0e10cSrcweir         {
702*cdf0e10cSrcweir             //the controller will be unlocked by the dialog when the dialog is told to do so
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir             // only activate object if not called via API (e.g. macro)
705*cdf0e10cSrcweir             pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
706*cdf0e10cSrcweir 
707*cdf0e10cSrcweir             //open wizard
708*cdf0e10cSrcweir             //@todo get context from calc if that has one
709*cdf0e10cSrcweir             uno::Reference< uno::XComponentContext > xContext(
710*cdf0e10cSrcweir                 ::cppu::defaultBootstrap_InitialComponentContext() );
711*cdf0e10cSrcweir             if(xContext.is())
712*cdf0e10cSrcweir             {
713*cdf0e10cSrcweir                 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
714*cdf0e10cSrcweir                 if(xMCF.is())
715*cdf0e10cSrcweir                 {
716*cdf0e10cSrcweir                     uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
717*cdf0e10cSrcweir                         xMCF->createInstanceWithContext(
718*cdf0e10cSrcweir                             rtl::OUString::createFromAscii("com.sun.star.comp.chart2.WizardDialog")
719*cdf0e10cSrcweir                             , xContext), uno::UNO_QUERY);
720*cdf0e10cSrcweir                     uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
721*cdf0e10cSrcweir                     if( xChartModel.is() && xInit.is() )
722*cdf0e10cSrcweir                     {
723*cdf0e10cSrcweir                         uno::Reference< awt::XWindow > xDialogParentWindow(0);
724*cdf0e10cSrcweir                         //	initialize dialog
725*cdf0e10cSrcweir                         uno::Sequence<uno::Any> aSeq(2);
726*cdf0e10cSrcweir                         uno::Any* pArray = aSeq.getArray();
727*cdf0e10cSrcweir                         beans::PropertyValue aParam1;
728*cdf0e10cSrcweir                         aParam1.Name = rtl::OUString::createFromAscii("ParentWindow");
729*cdf0e10cSrcweir                         aParam1.Value <<= uno::makeAny(xDialogParentWindow);
730*cdf0e10cSrcweir                         beans::PropertyValue aParam2;
731*cdf0e10cSrcweir                         aParam2.Name = rtl::OUString::createFromAscii("ChartModel");
732*cdf0e10cSrcweir                         aParam2.Value <<= uno::makeAny(xChartModel);
733*cdf0e10cSrcweir                         pArray[0] <<= uno::makeAny(aParam1);
734*cdf0e10cSrcweir                         pArray[1] <<= uno::makeAny(aParam2);
735*cdf0e10cSrcweir                         xInit->initialize( aSeq );
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir                         // try to set the dialog's position so it doesn't hide the chart
738*cdf0e10cSrcweir                         uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
739*cdf0e10cSrcweir                         if ( xDialogProps.is() )
740*cdf0e10cSrcweir                         {
741*cdf0e10cSrcweir                             try
742*cdf0e10cSrcweir                             {
743*cdf0e10cSrcweir                                 //get dialog size:
744*cdf0e10cSrcweir                                 awt::Size aDialogAWTSize;
745*cdf0e10cSrcweir                                 if( xDialogProps->getPropertyValue( ::rtl::OUString::createFromAscii("Size") )
746*cdf0e10cSrcweir                                     >>= aDialogAWTSize )
747*cdf0e10cSrcweir                                 {
748*cdf0e10cSrcweir                                     Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
749*cdf0e10cSrcweir                                     if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
750*cdf0e10cSrcweir                                     {
751*cdf0e10cSrcweir                                         //calculate and set new position
752*cdf0e10cSrcweir                                         Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect );
753*cdf0e10cSrcweir                                         xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("Position"),
754*cdf0e10cSrcweir                                             uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
755*cdf0e10cSrcweir                                     }
756*cdf0e10cSrcweir                                 }
757*cdf0e10cSrcweir                                 //tell the dialog to unlock controller
758*cdf0e10cSrcweir                                 xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("UnlockControllersOnExecute"),
759*cdf0e10cSrcweir                                             uno::makeAny( sal_True ) );
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir                             }
762*cdf0e10cSrcweir                             catch( uno::Exception& )
763*cdf0e10cSrcweir 		                    {
764*cdf0e10cSrcweir 			                    OSL_ASSERT( "Chart wizard couldn't be positioned automatically\n" );
765*cdf0e10cSrcweir 		                    }
766*cdf0e10cSrcweir                         }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir                         sal_Int16 nDialogRet = xDialog->execute();
769*cdf0e10cSrcweir                         if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
770*cdf0e10cSrcweir                         {
771*cdf0e10cSrcweir                             // leave OLE inplace mode and unmark
772*cdf0e10cSrcweir                             OSL_ASSERT( pViewShell );
773*cdf0e10cSrcweir                             OSL_ASSERT( pView );
774*cdf0e10cSrcweir                             pViewShell->DeactivateOle();
775*cdf0e10cSrcweir                             pView->UnmarkAll();
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir                             // old page view pointer is invalid after switching sheets
778*cdf0e10cSrcweir                             pPV = pView->GetSdrPageView();
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir                             // remove the chart
781*cdf0e10cSrcweir                             OSL_ASSERT( pPV );
782*cdf0e10cSrcweir                             SdrPage * pPage( pPV->GetPage());
783*cdf0e10cSrcweir                             OSL_ASSERT( pPage );
784*cdf0e10cSrcweir                             OSL_ASSERT( pObj );
785*cdf0e10cSrcweir                             if( pPage )
786*cdf0e10cSrcweir                                 pPage->RemoveObject( pObj->GetOrdNum());
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir                             bAddUndo = false;       // don't create the undo action for inserting
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir                             // leave the draw shell
791*cdf0e10cSrcweir                             pViewShell->SetDrawShell( sal_False );
792*cdf0e10cSrcweir                         }
793*cdf0e10cSrcweir                         else
794*cdf0e10cSrcweir                         {
795*cdf0e10cSrcweir                             OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK );
796*cdf0e10cSrcweir                             //@todo maybe move chart to different table
797*cdf0e10cSrcweir                         }
798*cdf0e10cSrcweir                     }
799*cdf0e10cSrcweir                     uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
800*cdf0e10cSrcweir                     if( xComponent.is())
801*cdf0e10cSrcweir                         xComponent->dispose();
802*cdf0e10cSrcweir                 }
803*cdf0e10cSrcweir             }
804*cdf0e10cSrcweir         }
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir         if ( bAddUndo )
807*cdf0e10cSrcweir         {
808*cdf0e10cSrcweir             // add undo action the same way as in SdrEditView::InsertObjectAtView
809*cdf0e10cSrcweir             // (using UndoActionHdl etc.)
810*cdf0e10cSrcweir             pView->AddUndo(pDoc->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
811*cdf0e10cSrcweir         }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir         // BM/IHA --
814*cdf0e10cSrcweir     }
815*cdf0e10cSrcweir }
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir /*************************************************************************
818*cdf0e10cSrcweir |*
819*cdf0e10cSrcweir |* FuInsertChart::Destruktor
820*cdf0e10cSrcweir |*
821*cdf0e10cSrcweir \************************************************************************/
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir FuInsertChart::~FuInsertChart()
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir /*************************************************************************
828*cdf0e10cSrcweir |*
829*cdf0e10cSrcweir |* FuInsertChart::Function aktivieren
830*cdf0e10cSrcweir |*
831*cdf0e10cSrcweir \************************************************************************/
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir void FuInsertChart::Activate()
834*cdf0e10cSrcweir {
835*cdf0e10cSrcweir 	FuPoor::Activate();
836*cdf0e10cSrcweir }
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir /*************************************************************************
839*cdf0e10cSrcweir |*
840*cdf0e10cSrcweir |* FuInsertChart::Function deaktivieren
841*cdf0e10cSrcweir |*
842*cdf0e10cSrcweir \************************************************************************/
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir void FuInsertChart::Deactivate()
845*cdf0e10cSrcweir {
846*cdf0e10cSrcweir 	FuPoor::Deactivate();
847*cdf0e10cSrcweir }
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 
850