fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / fuins2.cxx
blob226a4c41d4bad9fa256f978befa07cc48c7b23b6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
21 #include <com/sun/star/embed/Aspects.hpp>
22 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <sot/exchange.hxx>
26 #include <svl/globalnameitem.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <svl/stritem.hxx>
30 #include <svx/svdoole2.hxx>
31 #include <svx/pfiledlg.hxx>
32 #include <tools/urlobj.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <vcl/syschild.hxx>
35 #include <vcl/openglwin.hxx>
36 #include <svl/urihelper.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <svtools/insdlg.hxx>
39 #include <svtools/soerr.hxx>
40 #include <svtools/embedhlp.hxx>
41 #include <svx/svxdlg.hxx>
42 #include <comphelper/classids.hxx>
43 #include <svx/svdpagv.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdundo.hxx>
46 #include <sfx2/msgpool.hxx>
47 #include <svx/charthelper.hxx>
48 #include <scmod.hxx>
50 #include <cppuhelper/component_context.hxx>
51 #include <comphelper/processfactory.hxx>
52 #include <comphelper/storagehelper.hxx>
53 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
54 #include <com/sun/star/frame/XComponentLoader.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <com/sun/star/chart2/data/XDataProvider.hpp>
57 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
58 #include <com/sun/star/chart2/XChartDocument.hpp>
59 #include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
60 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
61 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
62 #include <com/sun/star/lang/XInitialization.hpp>
63 #include <com/sun/star/frame/XModel.hpp>
64 #include <com/sun/star/chart/ChartDataRowSource.hpp>
65 #include <cppuhelper/bootstrap.hxx>
67 using namespace ::com::sun::star;
69 #include "chart2uno.hxx"
70 #include "fuinsert.hxx"
71 #include "tabvwsh.hxx"
72 #include "sc.hrc"
73 #include "chartarr.hxx"
74 #include "docsh.hxx"
75 #include "document.hxx"
76 #include "undotab.hxx"
77 #include "chartlis.hxx"
78 #include "uiitems.hxx"
79 #include "globstr.hrc"
80 #include "drawview.hxx"
81 #include "markdata.hxx"
82 #include "gridwin.hxx"
83 #include <boost/scoped_ptr.hpp>
85 namespace {
87 void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData,
88 const OUString& rRangeParam )
90 ScDocShell* pDocShell = pViewData->GetDocShell();
91 ScDocument& rScDoc = pDocShell->GetDocument();
93 OUString aRangeString( rRangeParam );
94 if ( aRangeString.isEmpty() )
96 SCCOL nCol1 = 0;
97 SCROW nRow1 = 0;
98 SCTAB nTab1 = 0;
99 SCCOL nCol2 = 0;
100 SCROW nRow2 = 0;
101 SCTAB nTab2 = 0;
103 ScMarkData& rMark = pViewData->GetMarkData();
104 if ( !rMark.IsMarked() )
105 pViewData->GetView()->MarkDataArea( true );
107 if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
109 PutInOrder( nCol1, nCol2 );
110 PutInOrder( nRow1, nRow2 );
111 if (nCol2 >= nCol1 || nRow2 >= nRow1)
113 ScDocument* pDoc = pViewData->GetDocument();
114 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
116 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
117 aRangeString = aRange.Format(SCR_ABS_3D, &rScDoc);
122 if ( !aRangeString.isEmpty() )
124 // connect to Calc data (if no range string, leave chart alone, with its own data)
126 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
127 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
128 if( xCompSupp.is())
129 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
130 OSL_ASSERT( xReceiver.is());
131 if( xReceiver.is() )
133 uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( &rScDoc );
134 xReceiver->attachDataProvider( xDataProvider );
136 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
137 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
139 // Same behavior as with old chart: Always assume data series in columns
140 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
141 bool bHasCategories = false;
142 bool bFirstCellAsLabel = false;
144 // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
145 ScRangeListRef aRangeListRef( new ScRangeList );
146 aRangeListRef->Parse( aRangeString, &rScDoc, SCA_VALID, rScDoc.GetAddressConvention() );
147 if ( !aRangeListRef->empty() )
149 rScDoc.LimitChartIfAll( aRangeListRef ); // limit whole columns/rows to used area
151 // update string from modified ranges. The ranges must be in the current formula syntax.
152 OUString aTmpStr;
153 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, &rScDoc, rScDoc.GetAddressConvention() );
154 aRangeString = aTmpStr;
156 ScChartPositioner aChartPositioner( &rScDoc, aRangeListRef );
157 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
158 if( pPositionMap )
160 SCSIZE nRowCount = pPositionMap->GetRowCount();
161 if( 1==nRowCount )
162 eDataRowSource = chart::ChartDataRowSource_ROWS;
164 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
166 bHasCategories = aChartPositioner.HasRowHeaders();
167 bFirstCellAsLabel = aChartPositioner.HasColHeaders();
169 else // in case the default is changed
171 bHasCategories = aChartPositioner.HasColHeaders();
172 bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
176 uno::Sequence< beans::PropertyValue > aArgs( 4 );
177 aArgs[0] = beans::PropertyValue(
178 OUString("CellRangeRepresentation"), -1,
179 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
180 aArgs[1] = beans::PropertyValue(
181 OUString("HasCategories"), -1,
182 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
183 aArgs[2] = beans::PropertyValue(
184 OUString("FirstCellAsLabel"), -1,
185 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
186 aArgs[3] = beans::PropertyValue(
187 OUString("DataRowSource"), -1,
188 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
189 xReceiver->setArguments( aArgs );
191 // don't create chart listener here (range may be modified in chart dialog)
198 FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
199 SdrModel* pDoc, SfxRequest& rReq)
200 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
202 if( ! rReq.IsAPI() )
203 rReq.Done();
205 //! hier DLL's initalisieren, damit die Factories existieren?
207 uno::Reference < embed::XEmbeddedObject > xObj;
208 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
209 bool bIsFromFile = false;
210 OUString aName;
212 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
213 OUString aIconMediaType;
214 uno::Reference< io::XInputStream > xIconMetaFile;
216 sal_uInt16 nSlot = rReq.GetSlot();
217 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, false );
218 if ( nSlot == SID_INSERT_OBJECT && pNameItem )
220 SvGlobalName aClassName = pNameItem->GetValue();
221 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
223 else if ( nSlot == SID_INSERT_SMATH )
225 if ( SvtModuleOptions().IsMath() )
227 nSlot = SID_INSERT_OBJECT;
228 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName );
229 rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
232 else
234 SvObjectServerList aServerLst;
235 switch ( nSlot )
237 case SID_INSERT_OBJECT :
238 aServerLst.FillInsertObjects();
239 aServerLst.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen
240 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
241 case SID_INSERT_PLUGIN :
242 case SID_INSERT_FLOATINGFRAME :
244 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
245 boost::scoped_ptr<SfxAbstractInsertObjectDialog> pDlg(
246 pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
247 xStorage, &aServerLst ));
248 if ( pDlg )
250 pDlg->Execute();
251 xObj = pDlg->GetObject();
253 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
254 if ( xIconMetaFile.is() )
255 nAspect = embed::Aspects::MSOLE_ICON;
257 if ( xObj.is() )
258 pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
259 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
260 bIsFromFile = !pDlg->IsCreateNew();
263 break;
265 case SID_INSERT_SOUND :
266 case SID_INSERT_VIDEO :
268 // create special filedialog for plugins
269 SvxPluginFileDlg aPluginFileDialog(pWin, nSlot);
271 // open filedlg
272 if ( ERRCODE_NONE == aPluginFileDialog.Execute() )
274 // get URL
275 INetURLObject aURL;
276 aURL.SetSmartProtocol( INetProtocol::File );
277 if ( aURL.SetURL( aPluginFileDialog.GetPath() ) )
279 // create a plugin object
280 OUString aObjName;
281 SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
282 comphelper::EmbeddedObjectContainer aCnt( xStorage );
283 xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aObjName );
284 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
286 // set properties from dialog
287 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
288 if ( xSet.is() )
290 xSet->setPropertyValue("PluginURL",
291 uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
295 else
297 OSL_FAIL("Invalid URL!");
298 //! error message
299 //! can this happen???
306 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
307 if (xObj.is())
309 pView->UnmarkAll();
313 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
314 Size aSize;
315 MapMode aMap100( MAP_100TH_MM );
316 MapUnit aMapUnit = MAP_100TH_MM;
318 if ( nAspect == embed::Aspects::MSOLE_ICON )
320 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
321 aSize = aObjRef.GetSize( &aMap100 );
323 else
325 awt::Size aSz;
328 aSz = xObj->getVisualAreaSize( nAspect );
330 catch( embed::NoVisualAreaSizeException& )
332 // the default size will be set later
335 aSize = Size( aSz.Width, aSz.Height );
337 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
338 if (aSize.Height() == 0 || aSize.Width() == 0)
340 // Rechteck mit ausgewogenem Kantenverhaeltnis
341 aSize.Width() = 5000;
342 aSize.Height() = 5000;
343 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
344 aSz.Width = aTmp.Width();
345 aSz.Height = aTmp.Height();
346 xObj->setVisualAreaSize( nAspect, aSz );
348 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
349 aSize = vcl::Window::LogicToLogic( aTmp,
350 MapMode( aMapUnit ), aMap100 );
352 else
353 aSize = vcl::Window::LogicToLogic( aSize,
354 MapMode( aMapUnit ), aMap100 );
357 // Chart initialisieren ?
358 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
359 lcl_ChartInit( xObj, &pViewSh->GetViewData(), OUString() );
361 ScViewData& rData = pViewSh->GetViewData();
363 Point aPnt = pViewSh->GetInsertPos();
364 if ( rData.GetDocument()->IsNegativePage( rData.GetTabNo() ) )
365 aPnt.X() -= aSize.Width(); // move position to left edge
366 Rectangle aRect (aPnt, aSize);
367 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
368 SdrPageView* pPV = pView->GetSdrPageView();
369 pView->InsertObjectAtView(pObj, *pPV);
371 if ( nAspect != embed::Aspects::MSOLE_ICON )
373 // Math objects change their object size during InsertObject.
374 // New size must be set in SdrObject, or a wrong scale will be set at
375 // ActivateObject.
379 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
381 Size aNewSize( aSz.Width, aSz.Height );
382 aNewSize = OutputDevice::LogicToLogic( aNewSize, aMapUnit, MAP_100TH_MM );
384 if ( aNewSize != aSize )
386 aRect.SetSize( aNewSize );
387 pObj->SetLogicRect( aRect );
390 catch( embed::NoVisualAreaSizeException& )
394 if ( !rReq.IsAPI() )
396 // XXX Activate aus Makro ist toedlich !!! ???
397 if (bIsFromFile)
399 // Objekt ist selektiert, also Draw-Shell aktivieren
400 pViewShell->SetDrawShell( true );
402 else
404 pViewShell->ActivateObject( pObj, SVVERB_SHOW );
408 rReq.Done();
410 catch( uno::Exception& )
412 OSL_FAIL( "May need error handling here!\n" );
415 else
416 rReq.Ignore();
419 void FuInsertOLE::Activate()
421 FuPoor::Activate();
424 void FuInsertOLE::Deactivate()
426 FuPoor::Deactivate();
429 FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
430 SdrModel* pDoc, SfxRequest& rReq)
431 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
433 const SfxItemSet* pReqArgs = rReq.GetArgs();
435 if( ! rReq.IsAPI() )
436 rReq.Done();
438 if (!SvtModuleOptions().IsChart())
439 return;
441 // BM/IHA --
443 // get range
444 OUString aRangeString;
445 ScRange aPositionRange; // cell range for chart positioning
446 ScMarkData aMark = pViewSh->GetViewData().GetMarkData();
447 if( pReqArgs )
449 const SfxPoolItem* pItem;
450 if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
451 aRangeString = OUString( static_cast<const SfxStringItem*>(pItem)->GetValue());
453 aPositionRange = pViewSh->GetViewData().GetCurPos();
455 else
457 bool bAutomaticMark = false;
458 if ( !aMark.IsMarked() && !aMark.IsMultiMarked() )
460 pViewSh->GetViewData().GetView()->MarkDataArea( true );
461 bAutomaticMark = true;
464 ScMarkData aMultiMark( aMark );
465 aMultiMark.MarkToMulti();
467 ScRangeList aRanges;
468 aMultiMark.FillRangeListWithMarks( &aRanges, false );
469 OUString aStr;
470 ScDocument* pDocument = pViewSh->GetViewData().GetDocument();
471 aRanges.Format( aStr, SCR_ABS_3D, pDocument, pDocument->GetAddressConvention() );
472 aRangeString = aStr;
474 // get "total" range for positioning
475 if ( !aRanges.empty() )
477 aPositionRange = *aRanges[ 0 ];
478 for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i )
480 aPositionRange.ExtendTo( *aRanges[ i ] );
484 if(bAutomaticMark)
485 pViewSh->GetViewData().GetView()->Unmark();
488 // adapted old code
489 pView->UnmarkAll();
491 OUString aName;
492 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
494 uno::Reference < embed::XEmbeddedObject > xObj =
495 pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName );
497 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
498 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
499 if( xCompSupp.is())
500 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
502 uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
503 if (xChartDoc.is())
504 xChartDoc->createDefaultChart();
506 // lock the model to suppress any internal updates
507 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
508 if( xChartModel.is() )
509 xChartModel->lockControllers();
511 ScRangeListRef aDummy;
512 Rectangle aMarkDest;
513 SCTAB nMarkTab;
514 bool bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab );
516 // Objekt-Groesse
517 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
518 Size aSize( aSz.Width, aSz.Height );
520 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
522 bool bSizeCh = false;
523 if (bDrawRect && !aMarkDest.IsEmpty())
525 aSize = aMarkDest.GetSize();
526 bSizeCh = true;
528 if (aSize.Height() <= 0 || aSize.Width() <= 0)
530 aSize.Width() = 5000;
531 aSize.Height() = 5000;
532 bSizeCh = true;
534 if (bSizeCh)
536 aSize = vcl::Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
537 aSz.Width = aSize.Width();
538 aSz.Height = aSize.Height();
539 xObj->setVisualAreaSize( nAspect, aSz );
542 ScViewData& rData = pViewSh->GetViewData();
543 ScDocShell* pScDocSh = rData.GetDocShell();
544 ScDocument& rScDoc = pScDocSh->GetDocument();
545 bool bUndo (rScDoc.IsUndoEnabled());
547 if( pReqArgs )
549 const SfxPoolItem* pItem;
550 sal_uInt16 nToTable = 0;
552 if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
554 if ( pItem->ISA( SfxUInt16Item ) )
555 nToTable = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
556 else if ( pItem->ISA( SfxBoolItem ) )
558 // in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
559 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
561 if ( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
562 nToTable = static_cast<sal_uInt16>(rScDoc.GetTableCount());
563 else
564 nToTable = static_cast<sal_uInt16>(rData.GetTabNo());
567 else
569 if (bDrawRect)
570 nToTable = static_cast<sal_uInt16>(nMarkTab);
571 rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
574 // auf neue Tabelle ausgeben?
575 if ( nToTable == rScDoc.GetTableCount() )
577 // dann los...
578 OUString aTabName;
579 SCTAB nNewTab = rScDoc.GetTableCount();
581 rScDoc.CreateValidTabName( aTabName );
583 if ( rScDoc.InsertTab( nNewTab, aTabName ) )
585 if (bUndo)
587 bool bAppend = true;
588 pScDocSh->GetUndoManager()->AddUndoAction(
589 new ScUndoInsertTab( pScDocSh, nNewTab,
590 bAppend, aTabName ) );
593 pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
594 pViewSh->SetTabNo( nNewTab, true );
595 pScDocSh->PostPaintExtras(); //! erst hinterher ???
597 else
599 OSL_FAIL( "Could not create new table :-/" );
602 else if ( nToTable != rData.GetTabNo() )
604 pViewSh->SetTabNo( nToTable, true );
608 lcl_ChartInit( xObj, &rData, aRangeString ); // set source range, auto-detect column/row headers
610 // Objekt-Position
612 Point aStart;
613 if ( bDrawRect )
614 aStart = aMarkDest.TopLeft(); // marked by hand
615 else
617 // get chart position (from window size and data range)
618 aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
621 Rectangle aRect (aStart, aSize);
622 SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
623 SdrPageView* pPV = pView->GetSdrPageView();
625 // #i121334# This call will change the chart's default background fill from white to transparent.
626 // Add here again if this is wanted (see task description for details)
627 // ChartHelper::AdaptDefaultsForChart( xObj );
629 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
631 // use the page instead of the view to insert, so no undo action is created yet
632 SdrPage* pInsPage = pPV->GetPage();
633 pInsPage->InsertObject( pObj );
634 pView->UnmarkAllObj();
635 pView->MarkObj( pObj, pPV );
636 bool bAddUndo = true; // add undo action later, unless the dialog is canceled
638 if (rReq.IsAPI())
640 if( xChartModel.is() )
641 xChartModel->unlockControllers();
643 else
645 //the controller will be unlocked by the dialog when the dialog is told to do so
647 // only activate object if not called via API (e.g. macro)
648 pViewShell->ActivateObject( pObj, SVVERB_SHOW );
650 //open wizard
651 //@todo get context from calc if that has one
652 uno::Reference< uno::XComponentContext > xContext(
653 ::cppu::defaultBootstrap_InitialComponentContext() );
654 if(xContext.is())
656 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
657 if(xMCF.is())
659 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
660 xMCF->createInstanceWithContext(
661 OUString("com.sun.star.comp.chart2.WizardDialog")
662 , xContext), uno::UNO_QUERY);
663 uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
664 if( xChartModel.is() && xInit.is() )
666 uno::Reference< awt::XWindow > xDialogParentWindow(0);
667 // initialize dialog
668 uno::Sequence<uno::Any> aSeq(2);
669 uno::Any* pArray = aSeq.getArray();
670 beans::PropertyValue aParam1;
671 aParam1.Name = "ParentWindow";
672 aParam1.Value <<= uno::makeAny(xDialogParentWindow);
673 beans::PropertyValue aParam2;
674 aParam2.Name = "ChartModel";
675 aParam2.Value <<= uno::makeAny(xChartModel);
676 pArray[0] <<= uno::makeAny(aParam1);
677 pArray[1] <<= uno::makeAny(aParam2);
678 xInit->initialize( aSeq );
680 // try to set the dialog's position so it doesn't hide the chart
681 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
682 if ( xDialogProps.is() )
686 //get dialog size:
687 awt::Size aDialogAWTSize;
688 if( xDialogProps->getPropertyValue("Size")
689 >>= aDialogAWTSize )
691 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
692 if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
694 //calculate and set new position
695 Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect );
696 xDialogProps->setPropertyValue("Position",
697 uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
700 //tell the dialog to unlock controller
701 xDialogProps->setPropertyValue("UnlockControllersOnExecute",
702 uno::makeAny( sal_True ) );
705 catch( uno::Exception& )
707 OSL_FAIL( "Chart wizard couldn't be positioned automatically\n" );
711 sal_Int16 nDialogRet = xDialog->execute();
712 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
714 // leave OLE inplace mode and unmark
715 OSL_ASSERT( pViewShell );
716 OSL_ASSERT( pView );
717 pViewShell->DeactivateOle();
718 pView->UnmarkAll();
720 // old page view pointer is invalid after switching sheets
721 pPV = pView->GetSdrPageView();
723 // remove the chart
724 OSL_ASSERT( pPV );
725 SdrPage * pPage( pPV->GetPage());
726 OSL_ASSERT( pPage );
727 OSL_ASSERT( pObj );
728 if( pPage )
730 // Remove the OLE2 object from the sdr page.
731 SdrObject* pRemoved = pPage->RemoveObject(pObj->GetOrdNum());
732 OSL_ASSERT(pRemoved == pObj);
733 SdrObject::Free(pRemoved); // Don't forget to free it.
736 bAddUndo = false; // don't create the undo action for inserting
738 // leave the draw shell
739 pViewShell->SetDrawShell( false );
741 // reset marked cell area
743 pViewSh->GetViewData().GetViewShell()->SetMarkData(aMark);
745 else
747 OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK );
748 //@todo maybe move chart to different table
751 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
752 if( xComponent.is())
753 xComponent->dispose();
758 if ( bAddUndo )
760 // add undo action the same way as in SdrEditView::InsertObjectAtView
761 // (using UndoActionHdl etc.)
762 pView->AddUndo(new SdrUndoNewObj(*pObj));
765 // BM/IHA --
768 void FuInsertChart::Activate()
770 FuPoor::Activate();
773 void FuInsertChart::Deactivate()
775 FuPoor::Deactivate();
778 FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
779 SdrModel* pDoc, SfxRequest& rReq, const OUString& rURL):
780 FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
782 uno::Reference< io::XInputStream > xStorage = comphelper::OStorageHelper::GetInputStreamFromURL(
783 rURL, comphelper::getProcessComponentContext());
785 comphelper::EmbeddedObjectContainer& rObjContainer =
786 pViewShell->GetObjectShell()->GetEmbeddedObjectContainer();
788 OUString aName;
789 uno::Reference< embed::XEmbeddedObject > xObj = rObjContainer.InsertEmbeddedObject( xStorage, aName );
791 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
792 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
793 Size aSize( aSz.Width, aSz.Height );
795 ScRange aPositionRange = pViewSh->GetViewData().GetCurPos();
796 Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
797 Rectangle aRect (aStart, aSize);
798 SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
800 SdrPageView* pPV = pView->GetSdrPageView();
802 // use the page instead of the view to insert, so no undo action is created yet
803 SdrPage* pInsPage = pPV->GetPage();
804 pInsPage->InsertObject( pObj );
805 pView->UnmarkAllObj();
806 pView->MarkObj( pObj, pPV );
808 pViewShell->ActivateObject( pObj, SVVERB_SHOW );
811 void FuInsertChartFromFile::Activate()
813 FuPoor::Activate();
816 void FuInsertChartFromFile::Deactivate()
818 FuPoor::Deactivate();
821 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */