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>
49 #include <cppuhelper/component_context.hxx>
50 #include <comphelper/processfactory.hxx>
51 #include <comphelper/storagehelper.hxx>
52 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
53 #include <com/sun/star/frame/XComponentLoader.hpp>
54 #include <com/sun/star/beans/PropertyValue.hpp>
55 #include <com/sun/star/chart2/data/XDataProvider.hpp>
56 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
57 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
58 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
59 #include <com/sun/star/lang/XInitialization.hpp>
60 #include <com/sun/star/frame/XModel.hpp>
61 #include <com/sun/star/chart/ChartDataRowSource.hpp>
62 #include <cppuhelper/bootstrap.hxx>
64 using namespace ::com::sun::star
;
68 #include "chart2uno.hxx"
71 #include "fuinsert.hxx"
72 #include "tabvwsh.hxx"
74 #include "chartarr.hxx"
76 #include "document.hxx"
77 #include "undotab.hxx"
78 #include "chartlis.hxx"
79 #include "uiitems.hxx"
80 #include "globstr.hrc"
81 #include "drawview.hxx"
82 #include "markdata.hxx"
84 extern SdrObject
* pSkipPaintObj
; // output.cxx - dieses Objekt nicht zeichnen
88 void lcl_ChartInit( const uno::Reference
< embed::XEmbeddedObject
>& xObj
, ScViewData
* pViewData
,
89 const OUString
& rRangeParam
)
91 ScDocShell
* pDocShell
= pViewData
->GetDocShell();
92 ScDocument
* pScDoc
= pDocShell
->GetDocument();
94 OUString
aRangeString( rRangeParam
);
95 if ( aRangeString
.isEmpty() )
104 ScMarkData
& rMark
= pViewData
->GetMarkData();
105 if ( !rMark
.IsMarked() )
106 pViewData
->GetView()->MarkDataArea( true );
108 if ( pViewData
->GetSimpleArea( nCol1
,nRow1
,nTab1
, nCol2
,nRow2
,nTab2
) == SC_MARK_SIMPLE
)
110 PutInOrder( nCol1
, nCol2
);
111 PutInOrder( nRow1
, nRow2
);
112 if ( nCol2
>nCol1
|| nRow2
>nRow1
)
114 ScDocument
* pDoc
= pViewData
->GetDocument();
115 pDoc
->LimitChartArea( nTab1
, nCol1
,nRow1
, nCol2
,nRow2
);
117 ScRange
aRange( nCol1
, nRow1
, nTab1
, nCol2
, nRow2
, nTab2
);
118 aRange
.Format( aRangeString
, SCR_ABS_3D
, pScDoc
);
123 if ( !aRangeString
.isEmpty() )
125 // connect to Calc data (if no range string, leave chart alone, with its own data)
127 uno::Reference
< ::com::sun::star::chart2::data::XDataReceiver
> xReceiver
;
128 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
130 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
131 OSL_ASSERT( xReceiver
.is());
134 uno::Reference
< chart2::data::XDataProvider
> xDataProvider
= new ScChart2DataProvider( pScDoc
);
135 xReceiver
->attachDataProvider( xDataProvider
);
137 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( pDocShell
->GetModel(), uno::UNO_QUERY
);
138 xReceiver
->attachNumberFormatsSupplier( xNumberFormatsSupplier
);
140 // Same behavior as with old chart: Always assume data series in columns
141 chart::ChartDataRowSource eDataRowSource
= chart::ChartDataRowSource_COLUMNS
;
142 bool bHasCategories
= false;
143 bool bFirstCellAsLabel
= false;
145 // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
146 ScRangeListRef
aRangeListRef( new ScRangeList
);
147 aRangeListRef
->Parse( aRangeString
, pScDoc
, SCA_VALID
, pScDoc
->GetAddressConvention() );
148 if ( !aRangeListRef
->empty() )
150 pScDoc
->LimitChartIfAll( aRangeListRef
); // limit whole columns/rows to used area
152 // update string from modified ranges. The ranges must be in the current formula syntax.
154 aRangeListRef
->Format( aTmpStr
, SCR_ABS_3D
, pScDoc
, pScDoc
->GetAddressConvention() );
155 aRangeString
= aTmpStr
;
157 ScChartPositioner
aChartPositioner( pScDoc
, aRangeListRef
);
158 const ScChartPositionMap
* pPositionMap( aChartPositioner
.GetPositionMap() );
161 SCSIZE nRowCount
= pPositionMap
->GetRowCount();
163 eDataRowSource
= chart::ChartDataRowSource_ROWS
;
165 if ( eDataRowSource
== chart::ChartDataRowSource_COLUMNS
)
167 bHasCategories
= aChartPositioner
.HasRowHeaders();
168 bFirstCellAsLabel
= aChartPositioner
.HasColHeaders();
170 else // in case the default is changed
172 bHasCategories
= aChartPositioner
.HasColHeaders();
173 bFirstCellAsLabel
= aChartPositioner
.HasRowHeaders();
177 uno::Sequence
< beans::PropertyValue
> aArgs( 4 );
178 aArgs
[0] = beans::PropertyValue(
179 OUString("CellRangeRepresentation"), -1,
180 uno::makeAny( aRangeString
), beans::PropertyState_DIRECT_VALUE
);
181 aArgs
[1] = beans::PropertyValue(
182 OUString("HasCategories"), -1,
183 uno::makeAny( bHasCategories
), beans::PropertyState_DIRECT_VALUE
);
184 aArgs
[2] = beans::PropertyValue(
185 OUString("FirstCellAsLabel"), -1,
186 uno::makeAny( bFirstCellAsLabel
), beans::PropertyState_DIRECT_VALUE
);
187 aArgs
[3] = beans::PropertyValue(
188 OUString("DataRowSource"), -1,
189 uno::makeAny( eDataRowSource
), beans::PropertyState_DIRECT_VALUE
);
190 xReceiver
->setArguments( aArgs
);
192 // don't create chart listener here (range may be modified in chart dialog)
199 FuInsertOLE::FuInsertOLE(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
200 SdrModel
* pDoc
, SfxRequest
& rReq
)
201 : FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
206 //! hier DLL's initalisieren, damit die Factories existieren?
208 uno::Reference
< embed::XEmbeddedObject
> xObj
;
209 uno::Reference
< embed::XStorage
> xStorage
= comphelper::OStorageHelper::GetTemporaryStorage();
210 sal_Bool bIsFromFile
= false;
213 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
214 OUString aIconMediaType
;
215 uno::Reference
< io::XInputStream
> xIconMetaFile
;
218 sal_uInt16 nSlot
= rReq
.GetSlot();
219 SFX_REQUEST_ARG( rReq
, pNameItem
, SfxGlobalNameItem
, SID_INSERT_OBJECT
, false );
220 if ( nSlot
== SID_INSERT_OBJECT
&& pNameItem
)
222 SvGlobalName aClassName
= pNameItem
->GetValue();
223 xObj
= pViewShell
->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName
.GetByteSequence(), aName
);
225 else if ( nSlot
== SID_INSERT_SMATH
)
227 if ( SvtModuleOptions().IsMath() )
229 nSlot
= SID_INSERT_OBJECT
;
230 xObj
= pViewShell
->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60
).GetByteSequence(), aName
);
231 rReq
.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT
, SvGlobalName( SO3_SM_CLASSID_60
) ) );
236 SvObjectServerList aServerLst
;
239 case SID_INSERT_OBJECT
:
240 aServerLst
.FillInsertObjects();
241 aServerLst
.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen
242 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
243 case SID_INSERT_PLUGIN
:
244 case SID_INSERT_FLOATINGFRAME
:
246 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
247 SfxAbstractInsertObjectDialog
* pDlg
=
248 pFact
->CreateInsertObjectDialog( pViewShell
->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot
)->GetCommandString(),
249 xStorage
, &aServerLst
);
253 xObj
= pDlg
->GetObject();
255 xIconMetaFile
= pDlg
->GetIconIfIconified( &aIconMediaType
);
256 if ( xIconMetaFile
.is() )
257 nAspect
= embed::Aspects::MSOLE_ICON
;
260 pViewSh
->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj
, aName
);
261 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
262 bIsFromFile
= !pDlg
->IsCreateNew();
268 case SID_INSERT_SOUND
:
269 case SID_INSERT_VIDEO
:
271 // create special filedialog for plugins
272 SvxPluginFileDlg
aPluginFileDialog(pWin
, nSlot
);
275 if ( ERRCODE_NONE
== aPluginFileDialog
.Execute() )
279 aURL
.SetSmartProtocol( INET_PROT_FILE
);
280 if ( aURL
.SetURL( aPluginFileDialog
.GetPath() ) )
282 // create a plugin object
284 SvGlobalName
aClassId( SO3_PLUGIN_CLASSID
);
285 comphelper::EmbeddedObjectContainer
aCnt( xStorage
);
286 xObj
= aCnt
.CreateEmbeddedObject( aClassId
.GetByteSequence(), aObjName
);
287 if ( xObj
.is() && svt::EmbeddedObjectRef::TryRunningState( xObj
) )
289 // set properties from dialog
290 uno::Reference
< beans::XPropertySet
> xSet( xObj
->getComponent(), uno::UNO_QUERY
);
293 xSet
->setPropertyValue( OUString("PluginURL"),
294 uno::makeAny( OUString( aURL
.GetMainURL( INetURLObject::NO_DECODE
) ) ) );
300 OSL_FAIL("Invalid URL!");
302 //! can this happen???
309 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
316 ::svt::EmbeddedObjectRef
aObjRef( xObj
, nAspect
);
318 MapMode
aMap100( MAP_100TH_MM
);
319 MapUnit aMapUnit
= MAP_100TH_MM
;
321 if ( nAspect
== embed::Aspects::MSOLE_ICON
)
323 aObjRef
.SetGraphicStream( xIconMetaFile
, aIconMediaType
);
324 aSize
= aObjRef
.GetSize( &aMap100
);
331 aSz
= xObj
->getVisualAreaSize( nAspect
);
333 catch( embed::NoVisualAreaSizeException
& )
335 // the default size will be set later
338 aSize
= Size( aSz
.Width
, aSz
.Height
);
340 aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
341 if (aSize
.Height() == 0 || aSize
.Width() == 0)
343 // Rechteck mit ausgewogenem Kantenverhaeltnis
344 aSize
.Width() = 5000;
345 aSize
.Height() = 5000;
346 Size aTmp
= OutputDevice::LogicToLogic( aSize
, MAP_100TH_MM
, aMapUnit
);
347 aSz
.Width
= aTmp
.Width();
348 aSz
.Height
= aTmp
.Height();
349 xObj
->setVisualAreaSize( nAspect
, aSz
);
351 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
352 aSize
= Window::LogicToLogic( aTmp
,
353 MapMode( aMapUnit
), aMap100
);
356 aSize
= Window::LogicToLogic( aSize
,
357 MapMode( aMapUnit
), aMap100
);
360 // Chart initialisieren ?
361 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj
->getClassID() ) ) )
362 lcl_ChartInit( xObj
, pViewSh
->GetViewData(), OUString() );
364 ScViewData
* pData
= pViewSh
->GetViewData();
366 Point aPnt
= pViewSh
->GetInsertPos();
367 if ( pData
->GetDocument()->IsNegativePage( pData
->GetTabNo() ) )
368 aPnt
.X() -= aSize
.Width(); // move position to left edge
369 Rectangle
aRect (aPnt
, aSize
);
370 SdrOle2Obj
* pObj
= new SdrOle2Obj( aObjRef
, aName
, aRect
);
372 // Dieses Objekt nicht vor dem Aktivieren zeichnen
373 // (in MarkListHasChanged kommt ein Update)
375 pSkipPaintObj
= pObj
;
377 SdrPageView
* pPV
= pView
->GetSdrPageView();
378 pView
->InsertObjectAtView(pObj
, *pPV
);
380 if ( nAspect
!= embed::Aspects::MSOLE_ICON
)
382 // Math objects change their object size during InsertObject.
383 // New size must be set in SdrObject, or a wrong scale will be set at
388 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
390 Size
aNewSize( aSz
.Width
, aSz
.Height
);
391 aNewSize
= OutputDevice::LogicToLogic( aNewSize
, aMapUnit
, MAP_100TH_MM
);
393 if ( aNewSize
!= aSize
)
395 aRect
.SetSize( aNewSize
);
396 pObj
->SetLogicRect( aRect
);
399 catch( embed::NoVisualAreaSizeException
& )
405 // XXX Activate aus Makro ist toedlich !!! ???
408 // Objekt ist selektiert, also Draw-Shell aktivieren
409 pViewShell
->SetDrawShell( true );
413 pViewShell
->ActivateObject( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
414 pSkipPaintObj
= NULL
;
420 catch( uno::Exception
& )
422 OSL_FAIL( "May need error handling here!\n" );
429 void FuInsertOLE::Activate()
434 void FuInsertOLE::Deactivate()
436 FuPoor::Deactivate();
439 FuInsertChart::FuInsertChart(ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
440 SdrModel
* pDoc
, SfxRequest
& rReq
)
441 : FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
443 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
448 if( SvtModuleOptions().IsChart() )
450 // ----------------------------------------
454 OUString aRangeString
;
455 ScRange aPositionRange
; // cell range for chart positioning
458 const SfxPoolItem
* pItem
;
459 if( pReqArgs
->HasItem( FN_PARAM_5
, &pItem
) )
460 aRangeString
= OUString( ((const SfxStringItem
*)pItem
)->GetValue());
462 aPositionRange
= pViewSh
->GetViewData()->GetCurPos();
466 ScMarkData
& rMark
= pViewSh
->GetViewData()->GetMarkData();
467 bool bAutomaticMark
= false;
468 if ( !rMark
.IsMarked() && !rMark
.IsMultiMarked() )
470 pViewSh
->GetViewData()->GetView()->MarkDataArea( sal_True
);
471 bAutomaticMark
= true;
474 ScMarkData
aMultiMark( rMark
);
475 aMultiMark
.MarkToMulti();
478 aMultiMark
.FillRangeListWithMarks( &aRanges
, false );
480 ScDocument
* pDocument
= pViewSh
->GetViewData()->GetDocument();
481 aRanges
.Format( aStr
, SCR_ABS_3D
, pDocument
, pDocument
->GetAddressConvention() );
484 // get "total" range for positioning
485 if ( !aRanges
.empty() )
487 aPositionRange
= *aRanges
[ 0 ];
488 for ( size_t i
= 1, nCount
= aRanges
.size(); i
< nCount
; ++i
)
490 aPositionRange
.ExtendTo( *aRanges
[ i
] );
495 pViewSh
->GetViewData()->GetView()->Unmark();
498 // ----------------------------------------
503 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
505 uno::Reference
< embed::XEmbeddedObject
> xObj
=
506 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60
).GetByteSequence(), aName
);
508 uno::Reference
< ::com::sun::star::chart2::data::XDataReceiver
> xReceiver
;
509 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
511 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
513 // lock the model to suppress any internal updates
514 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
515 if( xChartModel
.is() )
516 xChartModel
->lockControllers();
518 ScRangeListRef aDummy
;
521 sal_Bool bDrawRect
= pViewShell
->GetChartArea( aDummy
, aMarkDest
, nMarkTab
);
524 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
525 Size
aSize( aSz
.Width
, aSz
.Height
);
527 MapUnit aMapUnit
= VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj
->getMapUnit( nAspect
) );
529 sal_Bool bSizeCh
= false;
530 if (bDrawRect
&& !aMarkDest
.IsEmpty())
532 aSize
= aMarkDest
.GetSize();
535 if (aSize
.Height() <= 0 || aSize
.Width() <= 0)
537 aSize
.Width() = 5000;
538 aSize
.Height() = 5000;
543 aSize
= Window::LogicToLogic( aSize
, MapMode( MAP_100TH_MM
), MapMode( aMapUnit
) );
544 aSz
.Width
= aSize
.Width();
545 aSz
.Height
= aSize
.Height();
546 xObj
->setVisualAreaSize( nAspect
, aSz
);
549 ScViewData
* pData
= pViewSh
->GetViewData();
550 ScDocShell
* pScDocSh
= pData
->GetDocShell();
551 ScDocument
* pScDoc
= pScDocSh
->GetDocument();
552 sal_Bool
bUndo (pScDoc
->IsUndoEnabled());
556 const SfxPoolItem
* pItem
;
557 sal_uInt16 nToTable
= 0;
559 if( pReqArgs
->HasItem( FN_PARAM_4
, &pItem
) )
561 if ( pItem
->ISA( SfxUInt16Item
) )
562 nToTable
= ((const SfxUInt16Item
*)pItem
)->GetValue();
563 else if ( pItem
->ISA( SfxBoolItem
) )
565 // in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
566 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
568 if ( ((const SfxBoolItem
*)pItem
)->GetValue() )
569 nToTable
= static_cast<sal_uInt16
>(pScDoc
->GetTableCount());
571 nToTable
= static_cast<sal_uInt16
>(pData
->GetTabNo());
577 nToTable
= static_cast<sal_uInt16
>(nMarkTab
);
578 rReq
.AppendItem( SfxUInt16Item( FN_PARAM_4
, nToTable
) );
581 // auf neue Tabelle ausgeben?
582 if ( nToTable
== pScDoc
->GetTableCount() )
586 SCTAB nNewTab
= pScDoc
->GetTableCount();
588 pScDoc
->CreateValidTabName( aTabName
);
590 if ( pScDoc
->InsertTab( nNewTab
, aTabName
) )
592 sal_Bool bAppend
= sal_True
;
596 pScDocSh
->GetUndoManager()->AddUndoAction(
597 new ScUndoInsertTab( pScDocSh
, nNewTab
,
598 bAppend
, aTabName
) );
601 pScDocSh
->Broadcast( ScTablesHint( SC_TAB_INSERTED
, nNewTab
) );
602 pViewSh
->SetTabNo( nNewTab
, sal_True
);
603 pScDocSh
->PostPaintExtras(); //! erst hinterher ???
607 OSL_FAIL( "Could not create new table :-/" );
610 else if ( nToTable
!= pData
->GetTabNo() )
612 pViewSh
->SetTabNo( nToTable
, sal_True
);
616 lcl_ChartInit( xObj
, pData
, aRangeString
); // set source range, auto-detect column/row headers
622 aStart
= aMarkDest
.TopLeft(); // marked by hand
625 // get chart position (from window size and data range)
626 aStart
= pViewSh
->GetChartInsertPos( aSize
, aPositionRange
);
629 Rectangle
aRect (aStart
, aSize
);
630 SdrOle2Obj
* pObj
= new SdrOle2Obj( svt::EmbeddedObjectRef( xObj
, nAspect
), aName
, aRect
);
632 // Dieses Objekt nicht vor dem Aktivieren zeichnen
633 // (in MarkListHasChanged kommt ein Update)
634 pSkipPaintObj
= pObj
;
636 SdrPageView
* pPV
= pView
->GetSdrPageView();
638 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
640 // use the page instead of the view to insert, so no undo action is created yet
641 SdrPage
* pInsPage
= pPV
->GetPage();
642 pInsPage
->InsertObject( pObj
);
643 pView
->UnmarkAllObj();
644 pView
->MarkObj( pObj
, pPV
);
645 bool bAddUndo
= true; // add undo action later, unless the dialog is canceled
649 if( xChartModel
.is() )
650 xChartModel
->unlockControllers();
654 //the controller will be unlocked by the dialog when the dialog is told to do so
656 // only activate object if not called via API (e.g. macro)
657 pViewShell
->ActivateObject( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
660 //@todo get context from calc if that has one
661 uno::Reference
< uno::XComponentContext
> xContext(
662 ::cppu::defaultBootstrap_InitialComponentContext() );
665 uno::Reference
< lang::XMultiComponentFactory
> xMCF( xContext
->getServiceManager() );
668 uno::Reference
< ui::dialogs::XExecutableDialog
> xDialog(
669 xMCF
->createInstanceWithContext(
670 OUString("com.sun.star.comp.chart2.WizardDialog")
671 , xContext
), uno::UNO_QUERY
);
672 uno::Reference
< lang::XInitialization
> xInit( xDialog
, uno::UNO_QUERY
);
673 if( xChartModel
.is() && xInit
.is() )
675 uno::Reference
< awt::XWindow
> xDialogParentWindow(0);
677 uno::Sequence
<uno::Any
> aSeq(2);
678 uno::Any
* pArray
= aSeq
.getArray();
679 beans::PropertyValue aParam1
;
680 aParam1
.Name
= OUString("ParentWindow");
681 aParam1
.Value
<<= uno::makeAny(xDialogParentWindow
);
682 beans::PropertyValue aParam2
;
683 aParam2
.Name
= OUString("ChartModel");
684 aParam2
.Value
<<= uno::makeAny(xChartModel
);
685 pArray
[0] <<= uno::makeAny(aParam1
);
686 pArray
[1] <<= uno::makeAny(aParam2
);
687 xInit
->initialize( aSeq
);
689 // try to set the dialog's position so it doesn't hide the chart
690 uno::Reference
< beans::XPropertySet
> xDialogProps( xDialog
, uno::UNO_QUERY
);
691 if ( xDialogProps
.is() )
696 awt::Size aDialogAWTSize
;
697 if( xDialogProps
->getPropertyValue( OUString("Size") )
700 Size
aDialogSize( aDialogAWTSize
.Width
, aDialogAWTSize
.Height
);
701 if ( aDialogSize
.Width() > 0 && aDialogSize
.Height() > 0 )
703 //calculate and set new position
704 Point aDialogPos
= pViewShell
->GetChartDialogPos( aDialogSize
, aRect
);
705 xDialogProps
->setPropertyValue( OUString("Position"),
706 uno::makeAny( awt::Point(aDialogPos
.getX(),aDialogPos
.getY()) ) );
709 //tell the dialog to unlock controller
710 xDialogProps
->setPropertyValue( OUString("UnlockControllersOnExecute"),
711 uno::makeAny( sal_True
) );
714 catch( uno::Exception
& )
716 OSL_FAIL( "Chart wizard couldn't be positioned automatically\n" );
720 sal_Int16 nDialogRet
= xDialog
->execute();
721 if( nDialogRet
== ui::dialogs::ExecutableDialogResults::CANCEL
)
723 // leave OLE inplace mode and unmark
724 OSL_ASSERT( pViewShell
);
726 pViewShell
->DeactivateOle();
729 // old page view pointer is invalid after switching sheets
730 pPV
= pView
->GetSdrPageView();
734 SdrPage
* pPage( pPV
->GetPage());
738 pPage
->RemoveObject( pObj
->GetOrdNum());
740 bAddUndo
= false; // don't create the undo action for inserting
742 // leave the draw shell
743 pViewShell
->SetDrawShell( false );
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
);
753 xComponent
->dispose();
760 // add undo action the same way as in SdrEditView::InsertObjectAtView
761 // (using UndoActionHdl etc.)
762 pView
->AddUndo(pDoc
->GetSdrUndoFactory().CreateUndoNewObject(*pObj
));
769 void FuInsertChart::Activate()
774 void FuInsertChart::Deactivate()
776 FuPoor::Deactivate();
779 FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell
* pViewSh
, Window
* pWin
, ScDrawView
* pViewP
,
780 SdrModel
* pDoc
, SfxRequest
& rReq
, const OUString
& rURL
):
781 FuPoor(pViewSh
, pWin
, pViewP
, pDoc
, rReq
)
783 uno::Reference
< io::XInputStream
> xStorage
= comphelper::OStorageHelper::GetInputStreamFromURL(
784 rURL
, comphelper::getProcessComponentContext());
786 comphelper::EmbeddedObjectContainer
& rObjContainer
=
787 pViewShell
->GetObjectShell()->GetEmbeddedObjectContainer();
790 uno::Reference
< embed::XEmbeddedObject
> xObj
= rObjContainer
.InsertEmbeddedObject( xStorage
, aName
);
792 const sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
793 awt::Size aSz
= xObj
->getVisualAreaSize( nAspect
);
794 Size
aSize( aSz
.Width
, aSz
.Height
);
796 ScRange aPositionRange
= pViewSh
->GetViewData()->GetCurPos();
797 Point aStart
= pViewSh
->GetChartInsertPos( aSize
, aPositionRange
);
798 Rectangle
aRect (aStart
, aSize
);
799 SdrOle2Obj
* pObj
= new SdrOle2Obj( svt::EmbeddedObjectRef( xObj
, nAspect
), aName
, aRect
);
801 pSkipPaintObj
= pObj
;
803 SdrPageView
* pPV
= pView
->GetSdrPageView();
805 // use the page instead of the view to insert, so no undo action is created yet
806 SdrPage
* pInsPage
= pPV
->GetPage();
807 pInsPage
->InsertObject( pObj
);
808 pView
->UnmarkAllObj();
809 pView
->MarkObj( pObj
, pPV
);
811 pViewShell
->ActivateObject( (SdrOle2Obj
*) pObj
, SVVERB_SHOW
);
814 void FuInsertChartFromFile::Activate()
819 void FuInsertChartFromFile::Deactivate()
821 FuPoor::Deactivate();
825 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */