merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / drawfunc / fuins2.cxx
blobdae97f1080f2ba0137a215f3662cba70a73a4f35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fuins2.cxx,v $
10 * $Revision: 1.31.20.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
36 #include <com/sun/star/embed/Aspects.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
39 //------------------------------------------------------------------------
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <sot/exchange.hxx>
43 #include <svtools/globalnameitem.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <sfx2/docfile.hxx>
46 #include <svtools/stritem.hxx>
47 #include <svx/svdoole2.hxx>
48 #include <svx/pfiledlg.hxx>
49 #include <tools/urlobj.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <svtools/urihelper.hxx>
52 #include <svtools/moduleoptions.hxx>
53 #include <svtools/insdlg.hxx>
54 #include <svtools/soerr.hxx>
55 #include <svx/svxdlg.hxx>
56 #include <sot/clsids.hxx>
57 #include <svx/svdpagv.hxx>
58 #include <svx/svdpage.hxx>
59 #include <svx/svdundo.hxx>
62 // BM/IHA --
63 #include <cppuhelper/component_context.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <comphelper/storagehelper.hxx>
66 #include <com/sun/star/beans/XPropertySet.hpp>
67 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
68 #include <com/sun/star/frame/XComponentLoader.hpp>
69 #include <com/sun/star/beans/PropertyValue.hpp>
70 #include <com/sun/star/chart2/data/XDataProvider.hpp>
71 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
72 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
73 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
74 #include <com/sun/star/lang/XInitialization.hpp>
75 #include <com/sun/star/frame/XModel.hpp>
76 #include <com/sun/star/chart/ChartDataRowSource.hpp>
77 #include <cppuhelper/bootstrap.hxx>
79 using namespace ::com::sun::star;
80 // BM/IHA --
82 // erAck
83 #include "chart2uno.hxx"
84 // erAck
86 #include "fuinsert.hxx"
87 #include "tabvwsh.hxx"
88 #include "sc.hrc"
89 #include "chartarr.hxx"
90 #include "docsh.hxx"
91 #include "document.hxx"
92 #include "undotab.hxx"
93 #include "chartlis.hxx"
94 #include "uiitems.hxx"
95 #include "globstr.hrc"
96 #include "drawview.hxx"
98 extern SdrObject* pSkipPaintObj; // output.cxx - dieses Objekt nicht zeichnen
100 //------------------------------------------------------------------------
102 #define IS_AVAILABLE(WhichId,ppItem) \
103 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
105 void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData,
106 const rtl::OUString& rRangeParam )
108 ScDocShell* pDocShell = pViewData->GetDocShell();
109 ScDocument* pScDoc = pDocShell->GetDocument();
111 rtl::OUString aRangeString( rRangeParam );
112 if ( !aRangeString.getLength() )
114 SCCOL nCol1 = 0;
115 SCROW nRow1 = 0;
116 SCTAB nTab1 = 0;
117 SCCOL nCol2 = 0;
118 SCROW nRow2 = 0;
119 SCTAB nTab2 = 0;
121 ScMarkData& rMark = pViewData->GetMarkData();
122 if ( !rMark.IsMarked() )
123 pViewData->GetView()->MarkDataArea( TRUE );
125 if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
127 PutInOrder( nCol1, nCol2 );
128 PutInOrder( nRow1, nRow2 );
129 if ( nCol2>nCol1 || nRow2>nRow1 )
131 ScDocument* pDoc = pViewData->GetDocument();
132 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
134 String aStr;
135 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
136 aRange.Format( aStr, SCR_ABS_3D, pScDoc );
137 aRangeString = aStr;
142 if ( aRangeString.getLength() )
144 // connect to Calc data (if no range string, leave chart alone, with its own data)
146 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
147 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
148 if( xCompSupp.is())
149 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
150 OSL_ASSERT( xReceiver.is());
151 if( xReceiver.is() )
153 uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( pScDoc );
154 xReceiver->attachDataProvider( xDataProvider );
156 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
157 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
159 // Same behavior as with old chart: Always assume data series in columns
160 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
161 bool bHasCategories = false;
162 bool bFirstCellAsLabel = false;
164 // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
165 ScRangeListRef aRangeListRef( new ScRangeList );
166 aRangeListRef->Parse( aRangeString, pScDoc );
167 if ( aRangeListRef->Count() )
169 pScDoc->LimitChartIfAll( aRangeListRef ); // limit whole columns/rows to used area
171 // update string from modified ranges. The ranges must be in the current formula syntax.
172 String aTmpStr;
173 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, pScDoc, pScDoc->GetAddressConvention() );
174 aRangeString = aTmpStr;
176 ScChartPositioner aChartPositioner( pScDoc, aRangeListRef );
177 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
178 if( pPositionMap )
180 SCSIZE nRowCount = pPositionMap->GetRowCount();
181 if( 1==nRowCount )
182 eDataRowSource = chart::ChartDataRowSource_ROWS;
184 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
186 bHasCategories = aChartPositioner.HasRowHeaders();
187 bFirstCellAsLabel = aChartPositioner.HasColHeaders();
189 else // in case the default is changed
191 bHasCategories = aChartPositioner.HasColHeaders();
192 bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
196 uno::Sequence< beans::PropertyValue > aArgs( 4 );
197 aArgs[0] = beans::PropertyValue(
198 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
199 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
200 aArgs[1] = beans::PropertyValue(
201 ::rtl::OUString::createFromAscii("HasCategories"), -1,
202 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
203 aArgs[2] = beans::PropertyValue(
204 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
205 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
206 aArgs[3] = beans::PropertyValue(
207 ::rtl::OUString::createFromAscii("DataRowSource"), -1,
208 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
209 xReceiver->setArguments( aArgs );
211 // don't create chart listener here (range may be modified in chart dialog)
216 /*************************************************************************
218 |* FuInsertOLE::Konstruktor
220 \************************************************************************/
222 FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
223 SdrModel* pDoc, SfxRequest& rReq)
224 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
226 if( ! rReq.IsAPI() )
227 rReq.Done();
229 //! hier DLL's initalisieren, damit die Factories existieren?
231 uno::Reference < embed::XEmbeddedObject > xObj;
232 uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
233 BOOL bIsFromFile = FALSE;
234 ::rtl::OUString aName;
236 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
237 ::rtl::OUString aIconMediaType;
238 uno::Reference< io::XInputStream > xIconMetaFile;
241 USHORT nSlot = rReq.GetSlot();
242 SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, sal_False );
243 if ( nSlot == SID_INSERT_OBJECT && pNameItem )
245 SvGlobalName aClassName = pNameItem->GetValue();
246 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
248 else if ( nSlot == SID_INSERT_SMATH )
250 if ( SvtModuleOptions().IsMath() )
252 nSlot = SID_INSERT_OBJECT;
253 xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName );
254 rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
257 else
259 SvObjectServerList aServerLst;
260 switch ( nSlot )
262 case SID_INSERT_OBJECT :
263 aServerLst.FillInsertObjects();
264 aServerLst.Remove( ScDocShell::Factory().GetClassId() ); // Starcalc nicht anzeigen
265 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
266 case SID_INSERT_PLUGIN :
267 case SID_INSERT_APPLET :
268 case SID_INSERT_FLOATINGFRAME :
270 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
271 SfxAbstractInsertObjectDialog* pDlg =
272 pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), nSlot,
273 xStorage, &aServerLst );
274 if ( pDlg )
276 pDlg->Execute();
277 xObj = pDlg->GetObject();
279 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
280 if ( xIconMetaFile.is() )
281 nAspect = embed::Aspects::MSOLE_ICON;
283 if ( xObj.is() )
284 pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
285 // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
286 bIsFromFile = !pDlg->IsCreateNew();
287 DELETEZ( pDlg );
290 break;
292 case SID_INSERT_SOUND :
293 case SID_INSERT_VIDEO :
295 // create special filedialog for plugins
296 SvxPluginFileDlg aPluginFileDialog(pWin, nSlot);
298 // open filedlg
299 if ( ERRCODE_NONE == aPluginFileDialog.Execute() )
301 // get URL
302 INetURLObject aURL;
303 aURL.SetSmartProtocol( INET_PROT_FILE );
304 if ( aURL.SetURL( aPluginFileDialog.GetPath() ) )
306 // create a plugin object
307 ::rtl::OUString aObjName;
308 SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
309 comphelper::EmbeddedObjectContainer aCnt( xStorage );
310 xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aObjName );
311 if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
313 // set properties from dialog
314 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
315 if ( xSet.is() )
317 xSet->setPropertyValue( ::rtl::OUString::createFromAscii("PluginURL"),
318 uno::makeAny( ::rtl::OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
322 else
324 DBG_ERROR("Invalid URL!");
325 //! error message
326 //! can this happen???
333 // SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
334 if (xObj.is())
336 pView->UnmarkAll();
340 ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
341 Size aSize;
342 MapMode aMap100( MAP_100TH_MM );
343 MapUnit aMapUnit = MAP_100TH_MM;
345 if ( nAspect == embed::Aspects::MSOLE_ICON )
347 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
348 aSize = aObjRef.GetSize( &aMap100 );
350 else
352 awt::Size aSz;
355 aSz = xObj->getVisualAreaSize( nAspect );
357 catch( embed::NoVisualAreaSizeException& )
359 // the default size will be set later
362 aSize = Size( aSz.Width, aSz.Height );
364 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
365 if (aSize.Height() == 0 || aSize.Width() == 0)
367 // Rechteck mit ausgewogenem Kantenverhaeltnis
368 aSize.Width() = 5000;
369 aSize.Height() = 5000;
370 Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
371 aSz.Width = aTmp.Width();
372 aSz.Height = aTmp.Height();
373 xObj->setVisualAreaSize( nAspect, aSz );
375 // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
376 aSize = Window::LogicToLogic( aTmp,
377 MapMode( aMapUnit ), aMap100 );
379 else
380 aSize = Window::LogicToLogic( aSize,
381 MapMode( aMapUnit ), aMap100 );
384 // Chart initialisieren ?
385 if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
386 lcl_ChartInit( xObj, pViewSh->GetViewData(), rtl::OUString() );
388 ScViewData* pData = pViewSh->GetViewData();
390 Point aPnt = pViewSh->GetInsertPos();
391 if ( pData->GetDocument()->IsNegativePage( pData->GetTabNo() ) )
392 aPnt.X() -= aSize.Width(); // move position to left edge
393 Rectangle aRect (aPnt, aSize);
394 SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
396 // Dieses Objekt nicht vor dem Aktivieren zeichnen
397 // (in MarkListHasChanged kommt ein Update)
398 if (!bIsFromFile)
399 pSkipPaintObj = pObj;
401 SdrPageView* pPV = pView->GetSdrPageView();
402 pView->InsertObjectAtView(pObj, *pPV);
404 if ( nAspect != embed::Aspects::MSOLE_ICON )
406 // #73279# Math objects change their object size during InsertObject.
407 // New size must be set in SdrObject, or a wrong scale will be set at
408 // ActivateObject.
412 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
414 Size aNewSize( aSz.Width, aSz.Height );
415 aNewSize = OutputDevice::LogicToLogic( aNewSize, aMapUnit, MAP_100TH_MM );
417 if ( aNewSize != aSize )
419 aRect.SetSize( aNewSize );
420 pObj->SetLogicRect( aRect );
423 catch( embed::NoVisualAreaSizeException& )
427 if ( !rReq.IsAPI() )
429 // XXX Activate aus Makro ist toedlich !!! ???
430 if (bIsFromFile)
432 // #45012# Objekt ist selektiert, also Draw-Shell aktivieren
433 pViewShell->SetDrawShell( TRUE );
435 else
437 pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
438 pSkipPaintObj = NULL;
442 rReq.Done();
444 catch( uno::Exception& )
446 OSL_ASSERT( "May need error handling here!\n" );
449 else
450 rReq.Ignore();
453 /*************************************************************************
455 |* FuInsertOLE::Destruktor
457 \************************************************************************/
459 FuInsertOLE::~FuInsertOLE()
463 /*************************************************************************
465 |* FuInsertOLE::Function aktivieren
467 \************************************************************************/
469 void FuInsertOLE::Activate()
471 FuPoor::Activate();
474 /*************************************************************************
476 |* FuInsertOLE::Function deaktivieren
478 \************************************************************************/
480 void FuInsertOLE::Deactivate()
482 FuPoor::Deactivate();
485 /*************************************************************************
487 |* FuInsertChart::Konstruktor
489 \************************************************************************/
491 FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
492 SdrModel* pDoc, SfxRequest& rReq)
493 : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
495 const SfxItemSet* pReqArgs = rReq.GetArgs();
497 if( ! rReq.IsAPI() )
498 rReq.Done();
500 if( SvtModuleOptions().IsChart() )
502 // ----------------------------------------
503 // BM/IHA --
505 // get range
506 ::rtl::OUString aRangeString;
507 ScRange aPositionRange; // cell range for chart positioning
508 if( pReqArgs )
510 const SfxPoolItem* pItem;
511 if( IS_AVAILABLE( FN_PARAM_5, &pItem ) )
512 aRangeString = ::rtl::OUString( ((const SfxStringItem*)pItem)->GetValue());
514 aPositionRange = pViewSh->GetViewData()->GetCurPos();
516 else
518 ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData();
519 bool bAutomaticMark = false;
520 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
522 pViewSh->GetViewData()->GetView()->MarkDataArea( TRUE );
523 bAutomaticMark = true;
526 ScMarkData aMultiMark( rMark );
527 aMultiMark.MarkToMulti();
529 ScRangeList aRanges;
530 aMultiMark.FillRangeListWithMarks( &aRanges, FALSE );
531 String aStr;
532 aRanges.Format( aStr, SCR_ABS_3D, pViewSh->GetViewData()->GetDocument() );
533 aRangeString = aStr;
535 // get "total" range for positioning
536 ULONG nCount = aRanges.Count();
537 if ( nCount > 0 )
539 aPositionRange = *aRanges.GetObject(0);
540 for (ULONG i=1; i<nCount; i++)
541 aPositionRange.ExtendTo( *aRanges.GetObject(i) );
544 if(bAutomaticMark)
545 pViewSh->GetViewData()->GetView()->Unmark();
548 // ----------------------------------------
549 // adapted old code
550 pView->UnmarkAll();
552 ::rtl::OUString aName;
553 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
555 uno::Reference < embed::XEmbeddedObject > xObj =
556 pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName );
558 uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
559 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
560 if( xCompSupp.is())
561 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
563 // lock the model to suppress any internal updates
564 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
565 if( xChartModel.is() )
566 xChartModel->lockControllers();
568 ScRangeListRef aDummy;
569 Rectangle aMarkDest;
570 SCTAB nMarkTab;
571 BOOL bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab );
573 // Objekt-Groesse
574 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
575 Size aSize( aSz.Width, aSz.Height );
577 MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
579 BOOL bSizeCh = FALSE;
580 if (bDrawRect && !aMarkDest.IsEmpty())
582 aSize = aMarkDest.GetSize();
583 bSizeCh = TRUE;
585 if (aSize.Height() <= 0 || aSize.Width() <= 0)
587 aSize.Width() = 5000;
588 aSize.Height() = 5000;
589 bSizeCh = TRUE;
591 if (bSizeCh)
593 aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
594 aSz.Width = aSize.Width();
595 aSz.Height = aSize.Height();
596 xObj->setVisualAreaSize( nAspect, aSz );
599 ScViewData* pData = pViewSh->GetViewData();
600 ScDocShell* pScDocSh = pData->GetDocShell();
601 ScDocument* pScDoc = pScDocSh->GetDocument();
602 BOOL bUndo (pScDoc->IsUndoEnabled());
604 if( pReqArgs )
606 const SfxPoolItem* pItem;
607 UINT16 nToTable = 0;
609 if( IS_AVAILABLE( FN_PARAM_4, &pItem ) )
611 if ( pItem->ISA( SfxUInt16Item ) )
612 nToTable = ((const SfxUInt16Item*)pItem)->GetValue();
613 else if ( pItem->ISA( SfxBoolItem ) )
615 // #46033# in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
616 // -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
618 if ( ((const SfxBoolItem*)pItem)->GetValue() )
619 nToTable = static_cast<UINT16>(pScDoc->GetTableCount());
620 else
621 nToTable = static_cast<UINT16>(pData->GetTabNo());
624 else
626 if (bDrawRect)
627 nToTable = static_cast<UINT16>(nMarkTab);
628 rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
631 // auf neue Tabelle ausgeben?
632 if ( nToTable == pScDoc->GetTableCount() )
634 // dann los...
635 String aTabName;
636 SCTAB nNewTab = pScDoc->GetTableCount();
638 pScDoc->CreateValidTabName( aTabName );
640 if ( pScDoc->InsertTab( nNewTab, aTabName ) )
642 BOOL bAppend = TRUE;
644 if (bUndo)
646 pScDocSh->GetUndoManager()->AddUndoAction(
647 new ScUndoInsertTab( pScDocSh, nNewTab,
648 bAppend, aTabName ) );
651 pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
652 pViewSh->SetTabNo( nNewTab, TRUE );
653 pScDocSh->PostPaintExtras(); //! erst hinterher ???
655 else
657 DBG_ERROR( "Could not create new table :-/" );
660 else if ( nToTable != pData->GetTabNo() )
662 pViewSh->SetTabNo( nToTable, TRUE );
666 lcl_ChartInit( xObj, pData, aRangeString ); // set source range, auto-detect column/row headers
668 // Objekt-Position
670 Point aStart;
671 if ( bDrawRect )
672 aStart = aMarkDest.TopLeft(); // marked by hand
673 else
675 // get chart position (from window size and data range)
676 aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
679 Rectangle aRect (aStart, aSize);
680 SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
682 // Dieses Objekt nicht vor dem Aktivieren zeichnen
683 // (in MarkListHasChanged kommt ein Update)
684 pSkipPaintObj = pObj;
686 SdrPageView* pPV = pView->GetSdrPageView();
688 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
690 // use the page instead of the view to insert, so no undo action is created yet
691 SdrPage* pInsPage = pPV->GetPage();
692 pInsPage->InsertObject( pObj );
693 pView->UnmarkAllObj();
694 pView->MarkObj( pObj, pPV );
695 bool bAddUndo = true; // add undo action later, unless the dialog is canceled
697 if (rReq.IsAPI())
699 if( xChartModel.is() )
700 xChartModel->unlockControllers();
702 else
704 //the controller will be unlocked by the dialog when the dialog is told to do so
706 // only activate object if not called via API (e.g. macro)
707 pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
709 //open wizard
710 //@todo get context from calc if that has one
711 uno::Reference< uno::XComponentContext > xContext(
712 ::cppu::defaultBootstrap_InitialComponentContext() );
713 if(xContext.is())
715 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
716 if(xMCF.is())
718 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
719 xMCF->createInstanceWithContext(
720 rtl::OUString::createFromAscii("com.sun.star.comp.chart2.WizardDialog")
721 , xContext), uno::UNO_QUERY);
722 uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
723 if( xChartModel.is() && xInit.is() )
725 uno::Reference< awt::XWindow > xDialogParentWindow(0);
726 // initialize dialog
727 uno::Sequence<uno::Any> aSeq(2);
728 uno::Any* pArray = aSeq.getArray();
729 beans::PropertyValue aParam1;
730 aParam1.Name = rtl::OUString::createFromAscii("ParentWindow");
731 aParam1.Value <<= uno::makeAny(xDialogParentWindow);
732 beans::PropertyValue aParam2;
733 aParam2.Name = rtl::OUString::createFromAscii("ChartModel");
734 aParam2.Value <<= uno::makeAny(xChartModel);
735 pArray[0] <<= uno::makeAny(aParam1);
736 pArray[1] <<= uno::makeAny(aParam2);
737 xInit->initialize( aSeq );
739 // try to set the dialog's position so it doesn't hide the chart
740 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
741 if ( xDialogProps.is() )
745 //get dialog size:
746 awt::Size aDialogAWTSize;
747 if( xDialogProps->getPropertyValue( ::rtl::OUString::createFromAscii("Size") )
748 >>= aDialogAWTSize )
750 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
751 if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
753 //calculate and set new position
754 Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect );
755 xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("Position"),
756 uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
759 //tell the dialog to unlock controller
760 xDialogProps->setPropertyValue( ::rtl::OUString::createFromAscii("UnlockControllersOnExecute"),
761 uno::makeAny( sal_True ) );
764 catch( uno::Exception& )
766 OSL_ASSERT( "Chart wizard couldn't be positioned automatically\n" );
770 sal_Int16 nDialogRet = xDialog->execute();
771 if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
773 // leave OLE inplace mode and unmark
774 OSL_ASSERT( pViewShell );
775 OSL_ASSERT( pView );
776 pViewShell->DeactivateOle();
777 pView->UnmarkAll();
779 // old page view pointer is invalid after switching sheets
780 pPV = pView->GetSdrPageView();
782 // remove the chart
783 OSL_ASSERT( pPV );
784 SdrPage * pPage( pPV->GetPage());
785 OSL_ASSERT( pPage );
786 OSL_ASSERT( pObj );
787 if( pPage )
788 pPage->RemoveObject( pObj->GetOrdNum());
790 bAddUndo = false; // don't create the undo action for inserting
792 // leave the draw shell
793 pViewShell->SetDrawShell( FALSE );
795 else
797 OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK );
798 //@todo maybe move chart to different table
801 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
802 if( xComponent.is())
803 xComponent->dispose();
808 if ( bAddUndo )
810 // add undo action the same way as in SdrEditView::InsertObjectAtView
811 // (using UndoActionHdl etc.)
812 pView->AddUndo(pDoc->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
815 // BM/IHA --
819 /*************************************************************************
821 |* FuInsertChart::Destruktor
823 \************************************************************************/
825 FuInsertChart::~FuInsertChart()
829 /*************************************************************************
831 |* FuInsertChart::Function aktivieren
833 \************************************************************************/
835 void FuInsertChart::Activate()
837 FuPoor::Activate();
840 /*************************************************************************
842 |* FuInsertChart::Function deaktivieren
844 \************************************************************************/
846 void FuInsertChart::Deactivate()
848 FuPoor::Deactivate();