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