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/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <sot/exchange.hxx>
28 #include <svl/globalnameitem.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svl/stritem.hxx>
31 #include <svx/svdoole2.hxx>
32 #include <unotools/moduleoptions.hxx>
33 #include <svtools/insdlg.hxx>
34 #include <svtools/embedhlp.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <comphelper/classids.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svdundo.hxx>
40 #include <sfx2/msgpool.hxx>
41 #include <sfx2/msg.hxx>
43 #include <sal/log.hxx>
44 #include <tools/diagnose_ex.h>
46 #include <comphelper/lok.hxx>
47 #include <comphelper/storagehelper.hxx>
48 #include <comphelper/propertysequence.hxx>
49 #include <sfx2/lokhelper.hxx>
50 #include <com/sun/star/embed/EmbedVerbs.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
53 #include <com/sun/star/chart2/XChartDocument.hpp>
54 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
55 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
56 #include <com/sun/star/lang/XInitialization.hpp>
57 #include <com/sun/star/frame/XModel.hpp>
58 #include <com/sun/star/chart/ChartDataRowSource.hpp>
59 #include <cppuhelper/bootstrap.hxx>
61 #include <PivotTableDataProvider.hxx>
62 #include <chart2uno.hxx>
63 #include <fuinsert.hxx>
64 #include <tabvwsh.hxx>
66 #include <chartpos.hxx>
68 #include <document.hxx>
69 #include <undotab.hxx>
70 #include <uiitems.hxx>
71 #include <drawview.hxx>
72 #include <markdata.hxx>
73 #include <dpobject.hxx>
81 void lcl_ChartInit(const uno::Reference
<embed::XEmbeddedObject
>& xObj
, ScViewData
* pViewData
,
82 const OUString
& rRangeParam
, bool bRangeIsPivotTable
)
84 ScDocShell
* pDocShell
= pViewData
->GetDocShell();
85 ScDocument
& rScDoc
= pDocShell
->GetDocument();
87 OUString
aRangeString(rRangeParam
);
89 if (aRangeString
.isEmpty() && !bRangeIsPivotTable
)
98 ScMarkData
& rMark
= pViewData
->GetMarkData();
99 if ( !rMark
.IsMarked() )
100 pViewData
->GetView()->MarkDataArea();
102 if ( pViewData
->GetSimpleArea( nCol1
,nRow1
,nTab1
, nCol2
,nRow2
,nTab2
) == SC_MARK_SIMPLE
)
104 PutInOrder( nCol1
, nCol2
);
105 PutInOrder( nRow1
, nRow2
);
106 if (nCol2
>= nCol1
|| nRow2
>= nRow1
)
108 ScDocument
* pDoc
= pViewData
->GetDocument();
109 pDoc
->LimitChartArea( nTab1
, nCol1
,nRow1
, nCol2
,nRow2
);
111 ScRange
aRange( nCol1
, nRow1
, nTab1
, nCol2
, nRow2
, nTab2
);
112 aRangeString
= aRange
.Format(ScRefFlags::RANGE_ABS_3D
, &rScDoc
, rScDoc
.GetAddressConvention());
117 if (!aRangeString
.isEmpty())
119 // connect to Calc data (if no range string, leave chart alone, with its own data)
121 uno::Reference
< css::chart2::data::XDataReceiver
> xReceiver
;
123 xReceiver
.set( xObj
->getComponent(), uno::UNO_QUERY
);
124 OSL_ASSERT( xReceiver
.is());
127 uno::Reference
<chart2::data::XDataProvider
> xDataProvider
;
128 if (bRangeIsPivotTable
)
130 std::unique_ptr
<sc::PivotTableDataProvider
> pPivotTableDataProvider(new sc::PivotTableDataProvider(&rScDoc
));
131 pPivotTableDataProvider
->setPivotTableName(aRangeString
);
132 xDataProvider
.set(pPivotTableDataProvider
.release());
136 xDataProvider
.set(new ScChart2DataProvider(&rScDoc
));
139 xReceiver
->attachDataProvider(xDataProvider
);
141 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( pDocShell
->GetModel(), uno::UNO_QUERY
);
142 xReceiver
->attachNumberFormatsSupplier( xNumberFormatsSupplier
);
144 // Same behavior as with old chart: Always assume data series in columns
145 chart::ChartDataRowSource eDataRowSource
= chart::ChartDataRowSource_COLUMNS
;
146 bool bHasCategories
= false;
147 bool bFirstCellAsLabel
= false;
149 // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
150 ScRangeListRef
aRangeListRef( new ScRangeList
);
151 aRangeListRef
->Parse( aRangeString
, &rScDoc
, rScDoc
.GetAddressConvention() );
152 if ( !aRangeListRef
->empty() )
154 rScDoc
.LimitChartIfAll( aRangeListRef
); // limit whole columns/rows to used area
156 // update string from modified ranges. The ranges must be in the current formula syntax.
158 aRangeListRef
->Format( aTmpStr
, ScRefFlags::RANGE_ABS_3D
, &rScDoc
, rScDoc
.GetAddressConvention() );
159 aRangeString
= aTmpStr
;
161 ScChartPositioner
aChartPositioner( &rScDoc
, aRangeListRef
);
162 const ScChartPositionMap
* pPositionMap( aChartPositioner
.GetPositionMap() );
165 SCSIZE nRowCount
= pPositionMap
->GetRowCount();
167 eDataRowSource
= chart::ChartDataRowSource_ROWS
;
169 if ( eDataRowSource
== chart::ChartDataRowSource_COLUMNS
)
171 bHasCategories
= aChartPositioner
.HasRowHeaders();
172 bFirstCellAsLabel
= aChartPositioner
.HasColHeaders();
174 else // in case the default is changed
176 bHasCategories
= aChartPositioner
.HasColHeaders();
177 bFirstCellAsLabel
= aChartPositioner
.HasRowHeaders();
181 uno::Sequence
< beans::PropertyValue
> aArgs( 4 );
182 aArgs
[0] = beans::PropertyValue(
183 "CellRangeRepresentation", -1,
184 uno::makeAny( aRangeString
), beans::PropertyState_DIRECT_VALUE
);
185 aArgs
[1] = beans::PropertyValue(
187 uno::makeAny( bHasCategories
), beans::PropertyState_DIRECT_VALUE
);
188 aArgs
[2] = beans::PropertyValue(
189 "FirstCellAsLabel", -1,
190 uno::makeAny( bFirstCellAsLabel
), beans::PropertyState_DIRECT_VALUE
);
191 aArgs
[3] = beans::PropertyValue(
193 uno::makeAny( eDataRowSource
), beans::PropertyState_DIRECT_VALUE
);
197 xReceiver
->setArguments( aArgs
);
199 catch (const lang::IllegalArgumentException
&)
201 // Can happen for invalid aRangeString, in which case a Chart
202 // will be created nevertheless and the range string can be
204 TOOLS_WARN_EXCEPTION("sc.ui",
205 "lcl_ChartInit - caught IllegalArgumentException might be due to aRangeString: " << aRangeString
);
208 // don't create chart listener here (range may be modified in chart dialog)
215 FuInsertOLE::FuInsertOLE(ScTabViewShell
& rViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
,
216 SdrModel
* pDoc
, SfxRequest
& rReq
)
217 : FuPoor(rViewSh
, pWin
, pViewP
, pDoc
, rReq
)
222 //! initialize DLLs here, so that the factories exist?
224 uno::Reference
< embed::XEmbeddedObject
> xObj
;
225 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
226 bool bIsFromFile
= false;
229 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
230 OUString aIconMediaType
;
231 uno::Reference
< io::XInputStream
> xIconMetaFile
;
233 const sal_uInt16 nSlot
= rReq
.GetSlot();
234 const SfxGlobalNameItem
* pNameItem
= rReq
.GetArg
<SfxGlobalNameItem
>(SID_INSERT_OBJECT
);
235 if ( nSlot
== SID_INSERT_OBJECT
&& pNameItem
)
237 const SvGlobalName
& aClassName
= pNameItem
->GetValue();
238 xObj
= rViewShell
.GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
240 else if ( nSlot
== SID_INSERT_SMATH
)
242 if ( SvtModuleOptions().IsMath() )
244 xObj
= rViewShell
.GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60
).GetByteSequence(), aName
);
245 rReq
.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT
, SvGlobalName( SO3_SM_CLASSID_60
) ) );
250 SvObjectServerList aServerLst
;
253 case SID_INSERT_OBJECT
:
254 aServerLst
.FillInsertObjects();
255 aServerLst
.Remove( ScDocShell::Factory().GetClassId() ); // Do not show Starcalc
256 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
257 [[fallthrough
]]; //TODO ???
258 case SID_INSERT_FLOATINGFRAME
:
260 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
261 ScopedVclPtr
<SfxAbstractInsertObjectDialog
> pDlg(
262 pFact
->CreateInsertObjectDialog( rViewShell
.GetFrameWeld(), SC_MOD()->GetSlotPool()->GetSlot(nSlot
)->GetCommandString(),
263 xStorage
, &aServerLst
));
267 xObj
= pDlg
->GetObject();
269 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
270 if ( xIconMetaFile
.is() )
271 nAspect
= embed::Aspects::MSOLE_ICON
;
274 rViewSh
.GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
275 // to activate DrawShell (no need to activate Object)
276 bIsFromFile
= !pDlg
->IsCreateNew();
284 // SvInsertObjectDialog (everything in one Dialog) are not used anymore
291 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
293 MapMode
aMap100( MapUnit::Map100thMM
);
294 MapUnit aMapUnit
= MapUnit::Map100thMM
;
296 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
298 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
299 aSize
= aObjRef
.GetSize( &aMap100
);
306 aSz
= xObj
->getVisualAreaSize( nAspect
);
308 catch( embed::NoVisualAreaSizeException
& )
310 // the default size will be set later
313 aSize
= Size( aSz
.Width
, aSz
.Height
);
315 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
316 if (aSize
.Height() == 0 || aSize
.Width() == 0)
318 // rectangle with balanced edge ratio
319 aSize
.setWidth( 5000 );
320 aSize
.setHeight( 5000 );
321 Size aTmp
= OutputDevice::LogicToLogic(aSize
, MapMode(MapUnit::Map100thMM
), MapMode(aMapUnit
));
322 aSz
.Width
= aTmp
.Width();
323 aSz
.Height
= aTmp
.Height();
324 xObj
->setVisualAreaSize( nAspect
, aSz
);
326 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
327 aSize
= vcl::Window::LogicToLogic( aTmp
,
328 MapMode( aMapUnit
), aMap100
);
331 aSize
= vcl::Window::LogicToLogic( aSize
,
332 MapMode( aMapUnit
), aMap100
);
335 // initialize chart ?
336 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj
->getClassID() ) ) )
337 lcl_ChartInit(xObj
, &rViewSh
.GetViewData(), OUString(), false);
339 ScViewData
& rData
= rViewSh
.GetViewData();
341 Point aPnt
= rViewSh
.GetInsertPos();
342 if ( rData
.GetDocument()->IsNegativePage( rData
.GetTabNo() ) )
343 aPnt
.AdjustX( -(aSize
.Width()) ); // move position to left edge
344 tools::Rectangle
aRect (aPnt
, aSize
);
345 SdrOle2Obj
* pObj
= new SdrOle2Obj(
346 *pDoc
, // TTTT should be reference
350 SdrPageView
* pPV
= pView
->GetSdrPageView();
351 bool bSuccess
= pView
->InsertObjectAtView(pObj
, *pPV
);
353 if (bSuccess
&& nAspect
!= embed::Aspects::MSOLE_ICON
)
355 // Math objects change their object size during InsertObject.
356 // New size must be set in SdrObject, or a wrong scale will be set at
361 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
363 Size
aNewSize( aSz
.Width
, aSz
.Height
);
364 aNewSize
= OutputDevice::LogicToLogic(aNewSize
, MapMode(aMapUnit
), MapMode(MapUnit::Map100thMM
));
366 if ( aNewSize
!= aSize
)
368 aRect
.SetSize( aNewSize
);
369 pObj
->SetLogicRect( aRect
);
372 catch( embed::NoVisualAreaSizeException
& )
378 // XXX Activate from macro is deadly !!! ???
381 // Object selected, activate Draw-Shell
382 rViewShell
.SetDrawShell( true );
386 rViewShell
.ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
392 catch( uno::Exception
& )
394 OSL_FAIL( "May need error handling here!" );
401 FuInsertChart::FuInsertChart(ScTabViewShell
& rViewSh
, vcl::Window
* pWin
, ScDrawView
* pViewP
,
402 SdrModel
* pDoc
, SfxRequest
& rReq
)
403 : FuPoor(rViewSh
, pWin
, pViewP
, pDoc
, rReq
)
405 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
410 if (!SvtModuleOptions().IsChart())
416 OUString aRangeString
;
417 bool bRangeIsPivotTable
= false;
418 ScRange aPositionRange
; // cell range for chart positioning
419 ScMarkData aMark
= rViewSh
.GetViewData().GetMarkData();
422 const SfxPoolItem
* pItem
;
423 if( pReqArgs
->HasItem( FN_PARAM_5
, &pItem
) )
424 aRangeString
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
426 aPositionRange
= rViewSh
.GetViewData().GetCurPos();
430 ScDocument
* pDocument
= rViewSh
.GetViewData().GetDocument();
431 ScDPObject
* pObject
= pDocument
->GetDPAtCursor(rViewSh
.GetViewData().GetCurX(),
432 rViewSh
.GetViewData().GetCurY(),
433 rViewSh
.GetViewData().GetTabNo());
436 aRangeString
= pObject
->GetName();
437 bRangeIsPivotTable
= true;
441 bool bAutomaticMark
= false;
442 if ( !aMark
.IsMarked() && !aMark
.IsMultiMarked() )
444 rViewSh
.GetViewData().GetView()->MarkDataArea();
445 bAutomaticMark
= true;
448 ScMarkData
aMultiMark( aMark
);
449 aMultiMark
.MarkToMulti();
452 aMultiMark
.FillRangeListWithMarks( &aRanges
, false );
454 aRanges
.Format( aStr
, ScRefFlags::RANGE_ABS_3D
, pDocument
, pDocument
->GetAddressConvention() );
457 // get "total" range for positioning
458 if ( !aRanges
.empty() )
460 aPositionRange
= aRanges
[ 0 ];
461 for ( size_t i
= 1, nCount
= aRanges
.size(); i
< nCount
; ++i
)
463 aPositionRange
.ExtendTo( aRanges
[ i
] );
468 rViewSh
.GetViewData().GetView()->Unmark();
476 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
478 uno::Reference
< embed::XEmbeddedObject
> xObj
=
479 rViewShell
.GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60
).GetByteSequence(), aName
);
481 uno::Reference
< css::chart2::data::XDataReceiver
> xReceiver
;
483 xReceiver
.set( xObj
->getComponent(), uno::UNO_QUERY
);
485 uno::Reference
<chart2::XChartDocument
> xChartDoc(xReceiver
, uno::UNO_QUERY
);
487 xChartDoc
->createDefaultChart();
489 // lock the model to suppress any internal updates
490 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
491 if( xChartModel
.is() )
492 xChartModel
->lockControllers();
495 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
496 Size
aSize( aSz
.Width
, aSz
.Height
);
498 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
500 bool bSizeCh
= false;
501 if (aSize
.Height() <= 0 || aSize
.Width() <= 0)
503 aSize
.setWidth( 5000 );
504 aSize
.setHeight( 5000 );
509 aSize
= vcl::Window::LogicToLogic( aSize
, MapMode( MapUnit::Map100thMM
), MapMode( aMapUnit
) );
510 aSz
.Width
= aSize
.Width();
511 aSz
.Height
= aSize
.Height();
512 xObj
->setVisualAreaSize( nAspect
, aSz
);
515 ScViewData
& rData
= rViewSh
.GetViewData();
516 ScDocShell
* pScDocSh
= rData
.GetDocShell();
517 ScDocument
& rScDoc
= pScDocSh
->GetDocument();
518 bool bUndo (rScDoc
.IsUndoEnabled());
522 const SfxPoolItem
* pItem
;
523 sal_uInt16 nToTable
= 0;
525 if( pReqArgs
->HasItem( FN_PARAM_4
, &pItem
) )
527 if ( auto pUInt16Item
= dynamic_cast<const SfxUInt16Item
*>( pItem
) )
528 nToTable
= pUInt16Item
->GetValue();
529 else if ( auto pBoolItem
= dynamic_cast<const SfxBoolItem
*>( pItem
) )
531 // In IDL for Basic FN_PARAM_4 means SfxBoolItem
532 // -> if set new table, else current table
534 if ( pBoolItem
->GetValue() )
535 nToTable
= static_cast<sal_uInt16
>(rScDoc
.GetTableCount());
537 nToTable
= static_cast<sal_uInt16
>(rData
.GetTabNo());
542 rReq
.AppendItem( SfxUInt16Item( FN_PARAM_4
, nToTable
) );
545 // Output on new table?
546 if ( nToTable
== rScDoc
.GetTableCount() )
550 SCTAB nNewTab
= rScDoc
.GetTableCount();
552 rScDoc
.CreateValidTabName( aTabName
);
554 if ( rScDoc
.InsertTab( nNewTab
, aTabName
) )
558 pScDocSh
->GetUndoManager()->AddUndoAction(
559 std::make_unique
<ScUndoInsertTab
>( pScDocSh
, nNewTab
,
560 true/*bAppend*/, aTabName
) );
563 pScDocSh
->Broadcast( ScTablesHint( SC_TAB_INSERTED
, nNewTab
) );
564 rViewSh
.SetTabNo( nNewTab
, true );
565 pScDocSh
->PostPaintExtras(); //! done afterwards ???
569 OSL_FAIL( "Could not create new table :-/" );
572 else if ( nToTable
!= rData
.GetTabNo() )
574 rViewSh
.SetTabNo( nToTable
, true );
578 lcl_ChartInit(xObj
, &rData
, aRangeString
, bRangeIsPivotTable
); // set source range, auto-detect column/row headers
582 // get chart position (from window size and data range)
583 Point aStart
= rViewSh
.GetChartInsertPos( aSize
, aPositionRange
);
585 tools::Rectangle
aRect (aStart
, aSize
);
586 SdrOle2Obj
* pObj
= new SdrOle2Obj(
587 *pDoc
, // TTTT should be reference
588 svt::EmbeddedObjectRef(xObj
, nAspect
),
591 SdrPageView
* pPV
= pView
->GetSdrPageView();
593 // #i121334# This call will change the chart's default background fill from white to transparent.
594 // Add here again if this is wanted (see task description for details)
595 // ChartHelper::AdaptDefaultsForChart( xObj );
597 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immediate redraw and asks the chart for a visual representation
599 // use the page instead of the view to insert, so no undo action is created yet
600 SdrPage
* pInsPage
= pPV
->GetPage();
601 pInsPage
->InsertObject( pObj
);
602 pView
->UnmarkAllObj();
603 pView
->MarkObj( pObj
, pPV
);
604 bool bAddUndo
= true; // add undo action later, unless the dialog is canceled
608 if( xChartModel
.is() )
609 xChartModel
->unlockControllers();
611 else if (!comphelper::LibreOfficeKit::isMobile(SfxLokHelper::getView()))
613 //the controller will be unlocked by the dialog when the dialog is told to do so
615 // only activate object if not called via API (e.g. macro)
616 if (!comphelper::LibreOfficeKit::isActive())
617 rViewShell
.ActivateObject(pObj
, embed::EmbedVerbs::MS_OLEVERB_SHOW
);
620 //@todo get context from calc if that has one
621 uno::Reference
< uno::XComponentContext
> xContext(
622 ::cppu::defaultBootstrap_InitialComponentContext() );
625 uno::Reference
< lang::XMultiComponentFactory
> xMCF( xContext
->getServiceManager() );
628 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog(
629 xMCF
->createInstanceWithContext(
630 "com.sun.star.comp.chart2.WizardDialog"
631 , xContext
), uno::UNO_QUERY
);
632 uno::Reference
< lang::XInitialization
> xInit( xDialog
, uno::UNO_QUERY
);
633 if( xChartModel
.is() && xInit
.is() )
635 uno::Sequence
<uno::Any
> aSeq(comphelper::InitAnyPropertySequence(
637 {"ParentWindow", uno::Any(uno::Reference
< awt::XWindow
>())},
638 {"ChartModel", uno::Any(xChartModel
)}
640 xInit
->initialize( aSeq
);
642 // try to set the dialog's position so it doesn't hide the chart
643 uno::Reference
< beans::XPropertySet
> xDialogProps( xDialog
, uno::UNO_QUERY
);
644 if ( xDialogProps
.is() )
649 awt::Size aDialogAWTSize
;
650 if( xDialogProps
->getPropertyValue("Size")
653 Size
aDialogSize( aDialogAWTSize
.Width
, aDialogAWTSize
.Height
);
654 if ( aDialogSize
.Width() > 0 && aDialogSize
.Height() > 0 )
656 //calculate and set new position
657 Point aDialogPos
= rViewShell
.GetChartDialogPos( aDialogSize
, aRect
);
658 xDialogProps
->setPropertyValue("Position",
659 uno::makeAny( awt::Point(aDialogPos
.getX(),aDialogPos
.getY()) ) );
662 //tell the dialog to unlock controller
663 xDialogProps
->setPropertyValue("UnlockControllersOnExecute",
664 uno::makeAny( true ) );
667 catch( uno::Exception
& )
669 OSL_FAIL( "Chart wizard couldn't be positioned automatically" );
673 sal_Int16 nDialogRet
= xDialog
->execute();
674 if( nDialogRet
== ui::dialogs::ExecutableDialogResults::CANCEL
)
676 // leave OLE inplace mode and unmark
678 rViewShell
.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 rViewShell
.SetDrawShell( false );
702 // reset marked cell area
704 rViewSh
.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(std::make_unique
<SdrUndoNewObj
>(*pObj
));
729 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */