1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <tools/urlobj.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <vcl/syschild.hxx>
34 #include <vcl/openglwin.hxx>
35 #include <svl/urihelper.hxx>
36 #include <unotools/moduleoptions.hxx>
37 #include <svtools/insdlg.hxx>
38 #include <svtools/soerr.hxx>
39 #include <svtools/embedhlp.hxx>
40 #include <svx/svxdlg.hxx>
41 #include <comphelper/classids.hxx>
42 #include <svx/svdpagv.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdundo.hxx>
45 #include <sfx2/msgpool.hxx>
46 #include <svx/charthelper.hxx>
49 #include <cppuhelper/component_context.hxx>
50 #include <comphelper/processfactory.hxx>
51 #include <comphelper/storagehelper.hxx>
52 #include <com/sun/star/embed/EmbedVerbs.hpp>
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"
73 #include "chartarr.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"
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() )
103 ScMarkData
& rMark
= pViewData
->GetMarkData();
104 if ( !rMark
.IsMarked() )
105 pViewData
->GetView()->MarkDataArea();
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(ScRefFlags::RANGE_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
< css::chart2::data::XDataReceiver
> xReceiver
;
127 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
129 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
130 OSL_ASSERT( 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
, ScRefFlags::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.
153 aRangeListRef
->Format( aTmpStr
, ScRefFlags::RANGE_ABS_3D
, &rScDoc
, rScDoc
.GetAddressConvention() );
154 aRangeString
= aTmpStr
;
156 ScChartPositioner
aChartPositioner( &rScDoc
, aRangeListRef
);
157 const ScChartPositionMap
* pPositionMap( aChartPositioner
.GetPositionMap() );
160 SCSIZE nRowCount
= pPositionMap
->GetRowCount();
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
)
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;
212 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
213 OUString aIconMediaType
;
214 uno::Reference
< io::XInputStream
> xIconMetaFile
;
216 const sal_uInt16 nSlot
= rReq
.GetSlot();
217 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
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 xObj
= pViewShell
->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60
).GetByteSequence(), aName
);
228 rReq
.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT
, SvGlobalName( SO3_SM_CLASSID_60
) ) );
233 SvObjectServerList aServerLst
;
236 case SID_INSERT_OBJECT
:
237 aServerLst
.FillInsertObjects();
238 aServerLst
.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen
239 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
240 SAL_FALLTHROUGH
; //TODO ???
241 case SID_INSERT_FLOATINGFRAME
:
243 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
244 std::unique_ptr
<SfxAbstractInsertObjectDialog
> pDlg(
245 pFact
->CreateInsertObjectDialog( pViewShell
->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot
)->GetCommandString(),
246 xStorage
, &aServerLst
));
250 xObj
= pDlg
->GetObject();
252 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
253 if ( xIconMetaFile
.is() )
254 nAspect
= embed::Aspects::MSOLE_ICON
;
257 pViewSh
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
258 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
259 bIsFromFile
= !pDlg
->IsCreateNew();
267 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
274 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
276 MapMode
aMap100( MAP_100TH_MM
);
277 MapUnit aMapUnit
= MAP_100TH_MM
;
279 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
281 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
282 aSize
= aObjRef
.GetSize( &aMap100
);
289 aSz
= xObj
->getVisualAreaSize( nAspect
);
291 catch( embed::NoVisualAreaSizeException
& )
293 // the default size will be set later
296 aSize
= Size( aSz
.Width
, aSz
.Height
);
298 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
299 if (aSize
.Height() == 0 || aSize
.Width() == 0)
301 // Rechteck mit ausgewogenem Kantenverhaeltnis
302 aSize
.Width() = 5000;
303 aSize
.Height() = 5000;
304 Size aTmp
= OutputDevice::LogicToLogic( aSize
, MAP_100TH_MM
, aMapUnit
);
305 aSz
.Width
= aTmp
.Width();
306 aSz
.Height
= aTmp
.Height();
307 xObj
->setVisualAreaSize( nAspect
, aSz
);
309 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
310 aSize
= vcl::Window::LogicToLogic( aTmp
,
311 MapMode( aMapUnit
), aMap100
);
314 aSize
= vcl::Window::LogicToLogic( aSize
,
315 MapMode( aMapUnit
), aMap100
);
318 // Chart initialisieren ?
319 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj
->getClassID() ) ) )
320 lcl_ChartInit( xObj
, &pViewSh
->GetViewData(), OUString() );
322 ScViewData
& rData
= pViewSh
->GetViewData();
324 Point aPnt
= pViewSh
->GetInsertPos();
325 if ( rData
.GetDocument()->IsNegativePage( rData
.GetTabNo() ) )
326 aPnt
.X() -= aSize
.Width(); // move position to left edge
327 Rectangle
aRect (aPnt
, aSize
);
328 SdrOle2Obj
* pObj
= new SdrOle2Obj( aObjRef
, aName
, aRect
);
329 SdrPageView
* pPV
= pView
->GetSdrPageView();
330 pView
->InsertObjectAtView(pObj
, *pPV
);
332 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
334 // Math objects change their object size during InsertObject.
335 // New size must be set in SdrObject, or a wrong scale will be set at
340 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
342 Size
aNewSize( aSz
.Width
, aSz
.Height
);
343 aNewSize
= OutputDevice::LogicToLogic( aNewSize
, aMapUnit
, MAP_100TH_MM
);
345 if ( aNewSize
!= aSize
)
347 aRect
.SetSize( aNewSize
);
348 pObj
->SetLogicRect( aRect
);
351 catch( embed::NoVisualAreaSizeException
& )
357 // XXX Activate aus Makro ist toedlich !!! ???
360 // Objekt ist selektiert, also Draw-Shell aktivieren
361 pViewShell
->SetDrawShell( true );
365 pViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
371 catch( uno::Exception
& )
373 OSL_FAIL( "May need error handling here!\n" );
380 void FuInsertOLE::Activate()
385 void FuInsertOLE::Deactivate()
387 FuPoor::Deactivate();
390 FuInsertChart::FuInsertChart(ScTabViewShell
* pViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
,
391 SdrModel
* pDoc
, SfxRequest
& rReq
)
392 : FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
394 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
399 if (!SvtModuleOptions().IsChart())
405 OUString aRangeString
;
406 ScRange aPositionRange
; // cell range for chart positioning
407 ScMarkData aMark
= pViewSh
->GetViewData().GetMarkData();
410 const SfxPoolItem
* pItem
;
411 if( pReqArgs
->HasItem( FN_PARAM_5
, &pItem
) )
412 aRangeString
= OUString( static_cast<const SfxStringItem
*>(pItem
)->GetValue());
414 aPositionRange
= pViewSh
->GetViewData().GetCurPos();
418 bool bAutomaticMark
= false;
419 if ( !aMark
.IsMarked() && !aMark
.IsMultiMarked() )
421 pViewSh
->GetViewData().GetView()->MarkDataArea();
422 bAutomaticMark
= true;
425 ScMarkData
aMultiMark( aMark
);
426 aMultiMark
.MarkToMulti();
429 aMultiMark
.FillRangeListWithMarks( &aRanges
, false );
431 ScDocument
* pDocument
= pViewSh
->GetViewData().GetDocument();
432 aRanges
.Format( aStr
, ScRefFlags::RANGE_ABS_3D
, pDocument
, pDocument
->GetAddressConvention() );
435 // get "total" range for positioning
436 if ( !aRanges
.empty() )
438 aPositionRange
= *aRanges
[ 0 ];
439 for ( size_t i
= 1, nCount
= aRanges
.size(); i
< nCount
; ++i
)
441 aPositionRange
.ExtendTo( *aRanges
[ i
] );
446 pViewSh
->GetViewData().GetView()->Unmark();
453 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
455 uno::Reference
< embed::XEmbeddedObject
> xObj
=
456 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60
).GetByteSequence(), aName
);
458 uno::Reference
< css::chart2::data::XDataReceiver
> xReceiver
;
459 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
461 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
463 uno::Reference
<chart2::XChartDocument
> xChartDoc(xReceiver
, uno::UNO_QUERY
);
465 xChartDoc
->createDefaultChart();
467 // lock the model to suppress any internal updates
468 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
469 if( xChartModel
.is() )
470 xChartModel
->lockControllers();
472 ScRangeListRef aDummy
;
475 bool bDrawRect
= pViewShell
->GetChartArea( aDummy
, aMarkDest
, nMarkTab
);
478 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
479 Size
aSize( aSz
.Width
, aSz
.Height
);
481 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
483 bool bSizeCh
= false;
484 if (bDrawRect
&& !aMarkDest
.IsEmpty())
486 aSize
= aMarkDest
.GetSize();
489 if (aSize
.Height() <= 0 || aSize
.Width() <= 0)
491 aSize
.Width() = 5000;
492 aSize
.Height() = 5000;
497 aSize
= vcl::Window::LogicToLogic( aSize
, MapMode( MAP_100TH_MM
), MapMode( aMapUnit
) );
498 aSz
.Width
= aSize
.Width();
499 aSz
.Height
= aSize
.Height();
500 xObj
->setVisualAreaSize( nAspect
, aSz
);
503 ScViewData
& rData
= pViewSh
->GetViewData();
504 ScDocShell
* pScDocSh
= rData
.GetDocShell();
505 ScDocument
& rScDoc
= pScDocSh
->GetDocument();
506 bool bUndo (rScDoc
.IsUndoEnabled());
510 const SfxPoolItem
* pItem
;
511 sal_uInt16 nToTable
= 0;
513 if( pReqArgs
->HasItem( FN_PARAM_4
, &pItem
) )
515 if ( dynamic_cast<const SfxUInt16Item
*>( pItem
) != nullptr )
516 nToTable
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
517 else if ( dynamic_cast<const SfxBoolItem
*>( pItem
) != nullptr )
519 // in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
520 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
522 if ( static_cast<const SfxBoolItem
*>(pItem
)->GetValue() )
523 nToTable
= static_cast<sal_uInt16
>(rScDoc
.GetTableCount());
525 nToTable
= static_cast<sal_uInt16
>(rData
.GetTabNo());
531 nToTable
= static_cast<sal_uInt16
>(nMarkTab
);
532 rReq
.AppendItem( SfxUInt16Item( FN_PARAM_4
, nToTable
) );
535 // auf neue Tabelle ausgeben?
536 if ( nToTable
== rScDoc
.GetTableCount() )
540 SCTAB nNewTab
= rScDoc
.GetTableCount();
542 rScDoc
.CreateValidTabName( aTabName
);
544 if ( rScDoc
.InsertTab( nNewTab
, aTabName
) )
549 pScDocSh
->GetUndoManager()->AddUndoAction(
550 new ScUndoInsertTab( pScDocSh
, nNewTab
,
551 bAppend
, aTabName
) );
554 pScDocSh
->Broadcast( ScTablesHint( SC_TAB_INSERTED
, nNewTab
) );
555 pViewSh
->SetTabNo( nNewTab
, true );
556 pScDocSh
->PostPaintExtras(); //! erst hinterher ???
560 OSL_FAIL( "Could not create new table :-/" );
563 else if ( nToTable
!= rData
.GetTabNo() )
565 pViewSh
->SetTabNo( nToTable
, true );
569 lcl_ChartInit( xObj
, &rData
, aRangeString
); // set source range, auto-detect column/row headers
575 aStart
= aMarkDest
.TopLeft(); // marked by hand
578 // get chart position (from window size and data range)
579 aStart
= pViewSh
->GetChartInsertPos( aSize
, aPositionRange
);
582 Rectangle
aRect (aStart
, aSize
);
583 SdrOle2Obj
* pObj
= new SdrOle2Obj( svt::EmbeddedObjectRef( xObj
, nAspect
), aName
, aRect
);
584 SdrPageView
* pPV
= pView
->GetSdrPageView();
586 // #i121334# This call will change the chart's default background fill from white to transparent.
587 // Add here again if this is wanted (see task description for details)
588 // ChartHelper::AdaptDefaultsForChart( xObj );
590 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
592 // use the page instead of the view to insert, so no undo action is created yet
593 SdrPage
* pInsPage
= pPV
->GetPage();
594 pInsPage
->InsertObject( pObj
);
595 pView
->UnmarkAllObj();
596 pView
->MarkObj( pObj
, pPV
);
597 bool bAddUndo
= true; // add undo action later, unless the dialog is canceled
601 if( xChartModel
.is() )
602 xChartModel
->unlockControllers();
606 //the controller will be unlocked by the dialog when the dialog is told to do so
608 // only activate object if not called via API (e.g. macro)
609 pViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
612 //@todo get context from calc if that has one
613 uno::Reference
< uno::XComponentContext
> xContext(
614 ::cppu::defaultBootstrap_InitialComponentContext() );
617 uno::Reference
< lang::XMultiComponentFactory
> xMCF( xContext
->getServiceManager() );
620 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog(
621 xMCF
->createInstanceWithContext(
622 "com.sun.star.comp.chart2.WizardDialog"
623 , xContext
), uno::UNO_QUERY
);
624 uno::Reference
< lang::XInitialization
> xInit( xDialog
, uno::UNO_QUERY
);
625 if( xChartModel
.is() && xInit
.is() )
627 uno::Reference
< awt::XWindow
> xDialogParentWindow(nullptr);
629 uno::Sequence
<uno::Any
> aSeq(2);
630 uno::Any
* pArray
= aSeq
.getArray();
631 beans::PropertyValue aParam1
;
632 aParam1
.Name
= "ParentWindow";
633 aParam1
.Value
<<= uno::makeAny(xDialogParentWindow
);
634 beans::PropertyValue aParam2
;
635 aParam2
.Name
= "ChartModel";
636 aParam2
.Value
<<= uno::makeAny(xChartModel
);
637 pArray
[0] <<= uno::makeAny(aParam1
);
638 pArray
[1] <<= uno::makeAny(aParam2
);
639 xInit
->initialize( aSeq
);
641 // try to set the dialog's position so it doesn't hide the chart
642 uno::Reference
< beans::XPropertySet
> xDialogProps( xDialog
, uno::UNO_QUERY
);
643 if ( xDialogProps
.is() )
648 awt::Size aDialogAWTSize
;
649 if( xDialogProps
->getPropertyValue("Size")
652 Size
aDialogSize( aDialogAWTSize
.Width
, aDialogAWTSize
.Height
);
653 if ( aDialogSize
.Width() > 0 && aDialogSize
.Height() > 0 )
655 //calculate and set new position
656 Point aDialogPos
= pViewShell
->GetChartDialogPos( aDialogSize
, aRect
);
657 xDialogProps
->setPropertyValue("Position",
658 uno::makeAny( awt::Point(aDialogPos
.getX(),aDialogPos
.getY()) ) );
661 //tell the dialog to unlock controller
662 xDialogProps
->setPropertyValue("UnlockControllersOnExecute",
663 uno::makeAny( true ) );
666 catch( uno::Exception
& )
668 OSL_FAIL( "Chart wizard couldn't be positioned automatically\n" );
672 sal_Int16 nDialogRet
= xDialog
->execute();
673 if( nDialogRet
== ui::dialogs::ExecutableDialogResults::CANCEL
)
675 // leave OLE inplace mode and unmark
676 OSL_ASSERT( pViewShell
);
678 pViewShell
->DeactivateOle();
681 // old page view pointer is invalid after switching sheets
682 pPV
= pView
->GetSdrPageView();
686 SdrPage
* pPage( pPV
->GetPage());
691 // Remove the OLE2 object from the sdr page.
692 SdrObject
* pRemoved
= pPage
->RemoveObject(pObj
->GetOrdNum());
693 OSL_ASSERT(pRemoved
== pObj
);
694 SdrObject::Free(pRemoved
); // Don't forget to free it.
697 bAddUndo
= false; // don't create the undo action for inserting
699 // leave the draw shell
700 pViewShell
->SetDrawShell( false );
702 // reset marked cell area
704 pViewSh
->GetViewData().GetViewShell()->SetMarkData(aMark
);
708 OSL_ASSERT( nDialogRet
== ui::dialogs::ExecutableDialogResults::OK
);
709 //@todo maybe move chart to different table
712 uno::Reference
< lang::XComponent
> xComponent( xDialog
, uno::UNO_QUERY
);
714 xComponent
->dispose();
721 // add undo action the same way as in SdrEditView::InsertObjectAtView
722 // (using UndoActionHdl etc.)
723 pView
->AddUndo(new SdrUndoNewObj(*pObj
));
729 void FuInsertChart::Activate()
734 void FuInsertChart::Deactivate()
736 FuPoor::Deactivate();
739 FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell
* pViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
,
740 SdrModel
* pDoc
, SfxRequest
& rReq
, const OUString
& rURL
):
741 FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
743 uno::Reference
< io::XInputStream
> xStorage
= comphelper::OStorageHelper::GetInputStreamFromURL(
744 rURL
, comphelper::getProcessComponentContext());
746 comphelper::EmbeddedObjectContainer
& rObjContainer
=
747 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer();
750 uno::Reference
< embed::XEmbeddedObject
> xObj
= rObjContainer
.InsertEmbeddedObject( xStorage
, aName
);
752 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
753 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
754 Size
aSize( aSz
.Width
, aSz
.Height
);
756 ScRange aPositionRange
= pViewSh
->GetViewData().GetCurPos();
757 Point aStart
= pViewSh
->GetChartInsertPos( aSize
, aPositionRange
);
758 Rectangle
aRect (aStart
, aSize
);
759 SdrOle2Obj
* pObj
= new SdrOle2Obj( svt::EmbeddedObjectRef( xObj
, nAspect
), aName
, aRect
);
761 SdrPageView
* pPV
= pView
->GetSdrPageView();
763 // use the page instead of the view to insert, so no undo action is created yet
764 SdrPage
* pInsPage
= pPV
->GetPage();
765 pInsPage
->InsertObject( pObj
);
766 pView
->UnmarkAllObj();
767 pView
->MarkObj( pObj
, pPV
);
769 pViewShell
->ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
772 void FuInsertChartFromFile::Activate()
777 void FuInsertChartFromFile::Deactivate()
779 FuPoor::Deactivate();
782 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */