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 //------------------------------------------------------------------------
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <sot/exchange.hxx>
28 #include <svl/globalnameitem.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/docfile.hxx>
31 #include <svl/stritem.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/pfiledlg.hxx>
34 #include <tools/urlobj.hxx>
35 #include <vcl/msgbox.hxx>
36 #include <svl/urihelper.hxx>
37 #include <unotools/moduleoptions.hxx>
38 #include <svtools/insdlg.hxx>
39 #include <svtools/soerr.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>
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/ui/dialogs/XExecutableDialog.hpp>
59 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
60 #include <com/sun/star/lang/XInitialization.hpp>
61 #include <com/sun/star/frame/XModel.hpp>
62 #include <com/sun/star/chart/ChartDataRowSource.hpp>
63 #include <cppuhelper/bootstrap.hxx>
65 using namespace ::com::sun::star
;
69 #include "chart2uno.hxx"
72 #include "fuinsert.hxx"
73 #include "tabvwsh.hxx"
75 #include "chartarr.hxx"
77 #include "document.hxx"
78 #include "undotab.hxx"
79 #include "chartlis.hxx"
80 #include "uiitems.hxx"
81 #include "globstr.hrc"
82 #include "drawview.hxx"
83 #include "markdata.hxx"
87 void lcl_ChartInit( const uno::Reference
< embed::XEmbeddedObject
>& xObj
, ScViewData
* pViewData
,
88 const OUString
& rRangeParam
)
90 ScDocShell
* pDocShell
= pViewData
->GetDocShell();
91 ScDocument
* pScDoc
= pDocShell
->GetDocument();
93 OUString
aRangeString( rRangeParam
);
94 if ( aRangeString
.isEmpty() )
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
, pScDoc
);
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
);
129 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
130 OSL_ASSERT( xReceiver
.is());
133 uno::Reference
< chart2::data::XDataProvider
> xDataProvider
= new ScChart2DataProvider( pScDoc
);
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
, pScDoc
, SCA_VALID
, pScDoc
->GetAddressConvention() );
147 if ( !aRangeListRef
->empty() )
149 pScDoc
->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
, SCR_ABS_3D
, pScDoc
, pScDoc
->GetAddressConvention() );
154 aRangeString
= aTmpStr
;
156 ScChartPositioner
aChartPositioner( pScDoc
, 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
, 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 sal_Bool bIsFromFile
= false;
212 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
213 OUString aIconMediaType
;
214 uno::Reference
< io::XInputStream
> xIconMetaFile
;
217 sal_uInt16 nSlot
= rReq
.GetSlot();
218 SFX_REQUEST_ARG( rReq
, pNameItem
, SfxGlobalNameItem
, SID_INSERT_OBJECT
, false );
219 if ( nSlot
== SID_INSERT_OBJECT
&& pNameItem
)
221 SvGlobalName aClassName
= pNameItem
->GetValue();
222 xObj
= pViewShell
->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
224 else if ( nSlot
== SID_INSERT_SMATH
)
226 if ( SvtModuleOptions().IsMath() )
228 nSlot
= SID_INSERT_OBJECT
;
229 xObj
= pViewShell
->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60
).GetByteSequence(), aName
);
230 rReq
.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT
, SvGlobalName( SO3_SM_CLASSID_60
) ) );
235 SvObjectServerList aServerLst
;
238 case SID_INSERT_OBJECT
:
239 aServerLst
.FillInsertObjects();
240 aServerLst
.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen
241 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
242 case SID_INSERT_PLUGIN
:
243 case SID_INSERT_FLOATINGFRAME
:
245 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
246 SfxAbstractInsertObjectDialog
* pDlg
=
247 pFact
->CreateInsertObjectDialog( pViewShell
->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot
)->GetCommandString(),
248 xStorage
, &aServerLst
);
252 xObj
= pDlg
->GetObject();
254 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
255 if ( xIconMetaFile
.is() )
256 nAspect
= embed::Aspects::MSOLE_ICON
;
259 pViewSh
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
260 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
261 bIsFromFile
= !pDlg
->IsCreateNew();
267 case SID_INSERT_SOUND
:
268 case SID_INSERT_VIDEO
:
270 // create special filedialog for plugins
271 SvxPluginFileDlg
aPluginFileDialog(pWin
, nSlot
);
274 if ( ERRCODE_NONE
== aPluginFileDialog
.Execute() )
278 aURL
.SetSmartProtocol( INET_PROT_FILE
);
279 if ( aURL
.SetURL( aPluginFileDialog
.GetPath() ) )
281 // create a plugin object
283 SvGlobalName
aClassId( SO3_PLUGIN_CLASSID
);
284 comphelper::EmbeddedObjectContainer
aCnt( xStorage
);
285 xObj
= aCnt
.CreateEmbeddedObject( aClassId
.GetByteSequence(), aObjName
);
286 if ( xObj
.is() && svt::EmbeddedObjectRef::TryRunningState( xObj
) )
288 // set properties from dialog
289 uno::Reference
< beans::XPropertySet
> xSet( xObj
->getComponent(), uno::UNO_QUERY
);
292 xSet
->setPropertyValue("PluginURL",
293 uno::makeAny( OUString( aURL
.GetMainURL( INetURLObject::NO_DECODE
) ) ) );
299 OSL_FAIL("Invalid URL!");
301 //! can this happen???
308 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
315 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
317 MapMode
aMap100( MAP_100TH_MM
);
318 MapUnit aMapUnit
= MAP_100TH_MM
;
320 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
322 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
323 aSize
= aObjRef
.GetSize( &aMap100
);
330 aSz
= xObj
->getVisualAreaSize( nAspect
);
332 catch( embed::NoVisualAreaSizeException
& )
334 // the default size will be set later
337 aSize
= Size( aSz
.Width
, aSz
.Height
);
339 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
340 if (aSize
.Height() == 0 || aSize
.Width() == 0)
342 // Rechteck mit ausgewogenem Kantenverhaeltnis
343 aSize
.Width() = 5000;
344 aSize
.Height() = 5000;
345 Size aTmp
= OutputDevice::LogicToLogic( aSize
, MAP_100TH_MM
, aMapUnit
);
346 aSz
.Width
= aTmp
.Width();
347 aSz
.Height
= aTmp
.Height();
348 xObj
->setVisualAreaSize( nAspect
, aSz
);
350 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
351 aSize
= Window::LogicToLogic( aTmp
,
352 MapMode( aMapUnit
), aMap100
);
355 aSize
= Window::LogicToLogic( aSize
,
356 MapMode( aMapUnit
), aMap100
);
359 // Chart initialisieren ?
360 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj
->getClassID() ) ) )
361 lcl_ChartInit( xObj
, pViewSh
->GetViewData(), OUString() );
363 ScViewData
* pData
= pViewSh
->GetViewData();
365 Point aPnt
= pViewSh
->GetInsertPos();
366 if ( pData
->GetDocument()->IsNegativePage( pData
->GetTabNo() ) )
367 aPnt
.X() -= aSize
.Width(); // move position to left edge
368 Rectangle
aRect (aPnt
, aSize
);
369 SdrOle2Obj
* pObj
= new SdrOle2Obj( aObjRef
, aName
, aRect
);
370 SdrPageView
* pPV
= pView
->GetSdrPageView();
371 pView
->InsertObjectAtView(pObj
, *pPV
);
373 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
375 // Math objects change their object size during InsertObject.
376 // New size must be set in SdrObject, or a wrong scale will be set at
381 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
383 Size
aNewSize( aSz
.Width
, aSz
.Height
);
384 aNewSize
= OutputDevice::LogicToLogic( aNewSize
, aMapUnit
, MAP_100TH_MM
);
386 if ( aNewSize
!= aSize
)
388 aRect
.SetSize( aNewSize
);
389 pObj
->SetLogicRect( aRect
);
392 catch( embed::NoVisualAreaSizeException
& )
398 // XXX Activate aus Makro ist toedlich !!! ???
401 // Objekt ist selektiert, also Draw-Shell aktivieren
402 pViewShell
->SetDrawShell( true );
406 pViewShell
->ActivateObject( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
412 catch( uno::Exception
& )
414 OSL_FAIL( "May need error handling here!\n" );
421 void FuInsertOLE::Activate()
426 void FuInsertOLE::Deactivate()
428 FuPoor::Deactivate();
431 FuInsertChart::FuInsertChart(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
432 SdrModel
* pDoc
, SfxRequest
& rReq
)
433 : FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
435 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
440 if( SvtModuleOptions().IsChart() )
442 // ----------------------------------------
446 OUString aRangeString
;
447 ScRange aPositionRange
; // cell range for chart positioning
450 const SfxPoolItem
* pItem
;
451 if( pReqArgs
->HasItem( FN_PARAM_5
, &pItem
) )
452 aRangeString
= OUString( ((const SfxStringItem
*)pItem
)->GetValue());
454 aPositionRange
= pViewSh
->GetViewData()->GetCurPos();
458 ScMarkData
& rMark
= pViewSh
->GetViewData()->GetMarkData();
459 bool bAutomaticMark
= false;
460 if ( !rMark
.IsMarked() && !rMark
.IsMultiMarked() )
462 pViewSh
->GetViewData()->GetView()->MarkDataArea( sal_True
);
463 bAutomaticMark
= true;
466 ScMarkData
aMultiMark( rMark
);
467 aMultiMark
.MarkToMulti();
470 aMultiMark
.FillRangeListWithMarks( &aRanges
, false );
472 ScDocument
* pDocument
= pViewSh
->GetViewData()->GetDocument();
473 aRanges
.Format( aStr
, SCR_ABS_3D
, pDocument
, pDocument
->GetAddressConvention() );
476 // get "total" range for positioning
477 if ( !aRanges
.empty() )
479 aPositionRange
= *aRanges
[ 0 ];
480 for ( size_t i
= 1, nCount
= aRanges
.size(); i
< nCount
; ++i
)
482 aPositionRange
.ExtendTo( *aRanges
[ i
] );
487 pViewSh
->GetViewData()->GetView()->Unmark();
490 // ----------------------------------------
495 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
497 uno::Reference
< embed::XEmbeddedObject
> xObj
=
498 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60
).GetByteSequence(), aName
);
500 uno::Reference
< ::com::sun::star::chart2::data::XDataReceiver
> xReceiver
;
501 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
503 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
505 // lock the model to suppress any internal updates
506 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
507 if( xChartModel
.is() )
508 xChartModel
->lockControllers();
510 ScRangeListRef aDummy
;
513 sal_Bool bDrawRect
= pViewShell
->GetChartArea( aDummy
, aMarkDest
, nMarkTab
);
516 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
517 Size
aSize( aSz
.Width
, aSz
.Height
);
519 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
521 sal_Bool bSizeCh
= false;
522 if (bDrawRect
&& !aMarkDest
.IsEmpty())
524 aSize
= aMarkDest
.GetSize();
527 if (aSize
.Height() <= 0 || aSize
.Width() <= 0)
529 aSize
.Width() = 5000;
530 aSize
.Height() = 5000;
535 aSize
= Window::LogicToLogic( aSize
, MapMode( MAP_100TH_MM
), MapMode( aMapUnit
) );
536 aSz
.Width
= aSize
.Width();
537 aSz
.Height
= aSize
.Height();
538 xObj
->setVisualAreaSize( nAspect
, aSz
);
541 ScViewData
* pData
= pViewSh
->GetViewData();
542 ScDocShell
* pScDocSh
= pData
->GetDocShell();
543 ScDocument
* pScDoc
= pScDocSh
->GetDocument();
544 sal_Bool
bUndo (pScDoc
->IsUndoEnabled());
548 const SfxPoolItem
* pItem
;
549 sal_uInt16 nToTable
= 0;
551 if( pReqArgs
->HasItem( FN_PARAM_4
, &pItem
) )
553 if ( pItem
->ISA( SfxUInt16Item
) )
554 nToTable
= ((const SfxUInt16Item
*)pItem
)->GetValue();
555 else if ( pItem
->ISA( SfxBoolItem
) )
557 // in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
558 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
560 if ( ((const SfxBoolItem
*)pItem
)->GetValue() )
561 nToTable
= static_cast<sal_uInt16
>(pScDoc
->GetTableCount());
563 nToTable
= static_cast<sal_uInt16
>(pData
->GetTabNo());
569 nToTable
= static_cast<sal_uInt16
>(nMarkTab
);
570 rReq
.AppendItem( SfxUInt16Item( FN_PARAM_4
, nToTable
) );
573 // auf neue Tabelle ausgeben?
574 if ( nToTable
== pScDoc
->GetTableCount() )
578 SCTAB nNewTab
= pScDoc
->GetTableCount();
580 pScDoc
->CreateValidTabName( aTabName
);
582 if ( pScDoc
->InsertTab( nNewTab
, aTabName
) )
584 sal_Bool bAppend
= sal_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
, sal_True
);
595 pScDocSh
->PostPaintExtras(); //! erst hinterher ???
599 OSL_FAIL( "Could not create new table :-/" );
602 else if ( nToTable
!= pData
->GetTabNo() )
604 pViewSh
->SetTabNo( nToTable
, sal_True
);
608 lcl_ChartInit( xObj
, pData
, aRangeString
); // set source range, auto-detect column/row headers
614 aStart
= aMarkDest
.TopLeft(); // marked by hand
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
640 if( xChartModel
.is() )
641 xChartModel
->unlockControllers();
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( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
651 //@todo get context from calc if that has one
652 uno::Reference
< uno::XComponentContext
> xContext(
653 ::cppu::defaultBootstrap_InitialComponentContext() );
656 uno::Reference
< lang::XMultiComponentFactory
> xMCF( xContext
->getServiceManager() );
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);
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() )
687 awt::Size aDialogAWTSize
;
688 if( xDialogProps
->getPropertyValue("Size")
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
);
717 pViewShell
->DeactivateOle();
720 // old page view pointer is invalid after switching sheets
721 pPV
= pView
->GetSdrPageView();
725 SdrPage
* pPage( pPV
->GetPage());
729 pPage
->RemoveObject( pObj
->GetOrdNum());
731 bAddUndo
= false; // don't create the undo action for inserting
733 // leave the draw shell
734 pViewShell
->SetDrawShell( false );
738 OSL_ASSERT( nDialogRet
== ui::dialogs::ExecutableDialogResults::OK
);
739 //@todo maybe move chart to different table
742 uno::Reference
< lang::XComponent
> xComponent( xDialog
, uno::UNO_QUERY
);
744 xComponent
->dispose();
751 // add undo action the same way as in SdrEditView::InsertObjectAtView
752 // (using UndoActionHdl etc.)
753 pView
->AddUndo(pDoc
->GetSdrUndoFactory().CreateUndoNewObject(*pObj
));
760 void FuInsertChart::Activate()
765 void FuInsertChart::Deactivate()
767 FuPoor::Deactivate();
770 FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
771 SdrModel
* pDoc
, SfxRequest
& rReq
, const OUString
& rURL
):
772 FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
774 uno::Reference
< io::XInputStream
> xStorage
= comphelper::OStorageHelper::GetInputStreamFromURL(
775 rURL
, comphelper::getProcessComponentContext());
777 comphelper::EmbeddedObjectContainer
& rObjContainer
=
778 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer();
781 uno::Reference
< embed::XEmbeddedObject
> xObj
= rObjContainer
.InsertEmbeddedObject( xStorage
, aName
);
783 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
784 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
785 Size
aSize( aSz
.Width
, aSz
.Height
);
787 ScRange aPositionRange
= pViewSh
->GetViewData()->GetCurPos();
788 Point aStart
= pViewSh
->GetChartInsertPos( aSize
, aPositionRange
);
789 Rectangle
aRect (aStart
, aSize
);
790 SdrOle2Obj
* pObj
= new SdrOle2Obj( svt::EmbeddedObjectRef( xObj
, nAspect
), aName
, aRect
);
792 SdrPageView
* pPV
= pView
->GetSdrPageView();
794 // use the page instead of the view to insert, so no undo action is created yet
795 SdrPage
* pInsPage
= pPV
->GetPage();
796 pInsPage
->InsertObject( pObj
);
797 pView
->UnmarkAllObj();
798 pView
->MarkObj( pObj
, pPV
);
800 pViewShell
->ActivateObject( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
803 void FuInsertChartFromFile::Activate()
808 void FuInsertChartFromFile::Deactivate()
810 FuPoor::Deactivate();
814 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */