LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - fuins2.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 378 0.3 %
Date: 2014-11-03 Functions: 2 12 16.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
      21             : #include <com/sun/star/embed/Aspects.hpp>
      22             : #include <com/sun/star/beans/XPropertySet.hpp>
      23             : 
      24             : #include <toolkit/helper/vclunohelper.hxx>
      25             : #include <sot/exchange.hxx>
      26             : #include <svl/globalnameitem.hxx>
      27             : #include <sfx2/viewfrm.hxx>
      28             : #include <sfx2/docfile.hxx>
      29             : #include <svl/stritem.hxx>
      30             : #include <svx/svdoole2.hxx>
      31             : #include <svx/pfiledlg.hxx>
      32             : #include <tools/urlobj.hxx>
      33             : #include <vcl/msgbox.hxx>
      34             : #include <vcl/syschild.hxx>
      35             : #include <vcl/openglwin.hxx>
      36             : #include <svl/urihelper.hxx>
      37             : #include <unotools/moduleoptions.hxx>
      38             : #include <svtools/insdlg.hxx>
      39             : #include <svtools/soerr.hxx>
      40             : #include <svtools/embedhlp.hxx>
      41             : #include <svx/svxdlg.hxx>
      42             : #include <comphelper/classids.hxx>
      43             : #include <svx/svdpagv.hxx>
      44             : #include <svx/svdpage.hxx>
      45             : #include <svx/svdundo.hxx>
      46             : #include <sfx2/msgpool.hxx>
      47             : #include <svx/charthelper.hxx>
      48             : #include <scmod.hxx>
      49             : 
      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/chart2/XChartDocument.hpp>
      59             : #include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
      60             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      61             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      62             : #include <com/sun/star/lang/XInitialization.hpp>
      63             : #include <com/sun/star/frame/XModel.hpp>
      64             : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      65             : #include <cppuhelper/bootstrap.hxx>
      66             : 
      67             : using namespace ::com::sun::star;
      68             : 
      69             : #include "chart2uno.hxx"
      70             : #include "fuinsert.hxx"
      71             : #include "tabvwsh.hxx"
      72             : #include "sc.hrc"
      73             : #include "chartarr.hxx"
      74             : #include "docsh.hxx"
      75             : #include "document.hxx"
      76             : #include "undotab.hxx"
      77             : #include "chartlis.hxx"
      78             : #include "uiitems.hxx"
      79             : #include "globstr.hrc"
      80             : #include "drawview.hxx"
      81             : #include "markdata.hxx"
      82             : #include "gridwin.hxx"
      83             : #include <boost/scoped_ptr.hpp>
      84             : 
      85             : namespace {
      86             : 
      87           0 : void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData,
      88             :                     const OUString& rRangeParam )
      89             : {
      90           0 :     ScDocShell* pDocShell = pViewData->GetDocShell();
      91           0 :     ScDocument& rScDoc = pDocShell->GetDocument();
      92             : 
      93           0 :     OUString aRangeString( rRangeParam );
      94           0 :     if ( aRangeString.isEmpty() )
      95             :     {
      96           0 :         SCCOL nCol1 = 0;
      97           0 :         SCROW nRow1 = 0;
      98           0 :         SCTAB nTab1 = 0;
      99           0 :         SCCOL nCol2 = 0;
     100           0 :         SCROW nRow2 = 0;
     101           0 :         SCTAB nTab2 = 0;
     102             : 
     103           0 :         ScMarkData& rMark = pViewData->GetMarkData();
     104           0 :         if ( !rMark.IsMarked() )
     105           0 :             pViewData->GetView()->MarkDataArea( true );
     106             : 
     107           0 :         if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
     108             :         {
     109           0 :             PutInOrder( nCol1, nCol2 );
     110           0 :             PutInOrder( nRow1, nRow2 );
     111           0 :             if (nCol2 >= nCol1 || nRow2 >= nRow1)
     112             :             {
     113           0 :                 ScDocument* pDoc = pViewData->GetDocument();
     114           0 :                 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
     115             : 
     116           0 :                 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
     117           0 :                 aRangeString = aRange.Format(SCR_ABS_3D, &rScDoc);
     118             :             }
     119             :         }
     120             :     }
     121             : 
     122           0 :     if ( !aRangeString.isEmpty() )
     123             :     {
     124             :         // connect to Calc data (if no range string, leave chart alone, with its own data)
     125             : 
     126           0 :         uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
     127           0 :         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
     128           0 :         if( xCompSupp.is())
     129           0 :             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
     130             :         OSL_ASSERT( xReceiver.is());
     131           0 :         if( xReceiver.is() )
     132             :         {
     133           0 :             uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( &rScDoc );
     134           0 :             xReceiver->attachDataProvider( xDataProvider );
     135             : 
     136           0 :             uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
     137           0 :             xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
     138             : 
     139             :             // Same behavior as with old chart: Always assume data series in columns
     140           0 :             chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
     141           0 :             bool bHasCategories = false;
     142           0 :             bool bFirstCellAsLabel = false;
     143             : 
     144             :             // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
     145           0 :             ScRangeListRef aRangeListRef( new ScRangeList );
     146           0 :             aRangeListRef->Parse( aRangeString, &rScDoc, SCA_VALID, rScDoc.GetAddressConvention() );
     147           0 :             if ( !aRangeListRef->empty() )
     148             :             {
     149           0 :                 rScDoc.LimitChartIfAll( aRangeListRef );               // limit whole columns/rows to used area
     150             : 
     151             :                 // update string from modified ranges.  The ranges must be in the current formula syntax.
     152           0 :                 OUString aTmpStr;
     153           0 :                 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, &rScDoc, rScDoc.GetAddressConvention() );
     154           0 :                 aRangeString = aTmpStr;
     155             : 
     156           0 :                 ScChartPositioner aChartPositioner( &rScDoc, aRangeListRef );
     157           0 :                 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
     158           0 :                 if( pPositionMap )
     159             :                 {
     160           0 :                     SCSIZE nRowCount = pPositionMap->GetRowCount();
     161           0 :                     if( 1==nRowCount )
     162           0 :                         eDataRowSource = chart::ChartDataRowSource_ROWS;
     163             :                 }
     164           0 :                 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
     165             :                 {
     166           0 :                     bHasCategories = aChartPositioner.HasRowHeaders();
     167           0 :                     bFirstCellAsLabel = aChartPositioner.HasColHeaders();
     168             :                 }
     169             :                 else    // in case the default is changed
     170             :                 {
     171           0 :                     bHasCategories = aChartPositioner.HasColHeaders();
     172           0 :                     bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
     173           0 :                 }
     174             :             }
     175             : 
     176           0 :             uno::Sequence< beans::PropertyValue > aArgs( 4 );
     177           0 :             aArgs[0] = beans::PropertyValue(
     178             :                 OUString("CellRangeRepresentation"), -1,
     179           0 :                 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
     180           0 :             aArgs[1] = beans::PropertyValue(
     181             :                 OUString("HasCategories"), -1,
     182           0 :                 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
     183           0 :             aArgs[2] = beans::PropertyValue(
     184             :                 OUString("FirstCellAsLabel"), -1,
     185           0 :                 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
     186           0 :             aArgs[3] = beans::PropertyValue(
     187             :                 OUString("DataRowSource"), -1,
     188           0 :                 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
     189           0 :             xReceiver->setArguments( aArgs );
     190             : 
     191             :             // don't create chart listener here (range may be modified in chart dialog)
     192           0 :         }
     193           0 :     }
     194           0 : }
     195             : 
     196             : }
     197             : 
     198           0 : FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
     199             :            SdrModel* pDoc, SfxRequest& rReq)
     200           0 :     : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
     201             : {
     202           0 :     if( ! rReq.IsAPI() )
     203           0 :         rReq.Done();
     204             : 
     205             :     //! hier DLL's initalisieren, damit die Factories existieren?
     206             : 
     207           0 :     uno::Reference < embed::XEmbeddedObject > xObj;
     208           0 :     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
     209           0 :     bool bIsFromFile = false;
     210           0 :     OUString aName;
     211             : 
     212           0 :     sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     213           0 :     OUString aIconMediaType;
     214           0 :     uno::Reference< io::XInputStream > xIconMetaFile;
     215             : 
     216           0 :     sal_uInt16 nSlot = rReq.GetSlot();
     217           0 :     SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, false );
     218           0 :     if ( nSlot == SID_INSERT_OBJECT && pNameItem )
     219             :     {
     220           0 :         SvGlobalName aClassName = pNameItem->GetValue();
     221           0 :         xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
     222             :     }
     223           0 :     else if ( nSlot == SID_INSERT_SMATH )
     224             :     {
     225           0 :         if ( SvtModuleOptions().IsMath() )
     226             :         {
     227           0 :             nSlot = SID_INSERT_OBJECT;
     228           0 :             xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName );
     229           0 :             rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
     230             :         }
     231             :     }
     232             :     else
     233             :     {
     234           0 :         SvObjectServerList aServerLst;
     235           0 :         switch ( nSlot )
     236             :         {
     237             :             case SID_INSERT_OBJECT :
     238           0 :                 aServerLst.FillInsertObjects();
     239           0 :                 aServerLst.Remove( ScDocShell::Factory().GetClassId() );   // Starcalc nicht anzeigen
     240             :                 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
     241             :             case SID_INSERT_PLUGIN :
     242             :             case SID_INSERT_FLOATINGFRAME :
     243             :             {
     244           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     245             :                 boost::scoped_ptr<SfxAbstractInsertObjectDialog> pDlg(
     246           0 :                         pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
     247           0 :                         xStorage, &aServerLst ));
     248           0 :                 if ( pDlg )
     249             :                 {
     250           0 :                     pDlg->Execute();
     251           0 :                     xObj = pDlg->GetObject();
     252             : 
     253           0 :                     xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
     254           0 :                     if ( xIconMetaFile.is() )
     255           0 :                         nAspect = embed::Aspects::MSOLE_ICON;
     256             : 
     257           0 :                     if ( xObj.is() )
     258           0 :                         pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     259             :                     // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
     260           0 :                     bIsFromFile = !pDlg->IsCreateNew();
     261             :                 }
     262             : 
     263           0 :                 break;
     264             :             }
     265             :             case SID_INSERT_SOUND :
     266             :             case SID_INSERT_VIDEO :
     267             :             {
     268             :                 // create special filedialog for plugins
     269           0 :                 SvxPluginFileDlg aPluginFileDialog(pWin, nSlot);
     270             : 
     271             :                 // open filedlg
     272           0 :                 if ( ERRCODE_NONE == aPluginFileDialog.Execute() )
     273             :                 {
     274             :                     // get URL
     275           0 :                     INetURLObject aURL;
     276           0 :                     aURL.SetSmartProtocol( INET_PROT_FILE );
     277           0 :                     if ( aURL.SetURL( aPluginFileDialog.GetPath() ) )
     278             :                     {
     279             :                         // create a plugin object
     280           0 :                         OUString aObjName;
     281           0 :                         SvGlobalName aClassId( SO3_PLUGIN_CLASSID );
     282           0 :                         comphelper::EmbeddedObjectContainer aCnt( xStorage );
     283           0 :                         xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aObjName );
     284           0 :                         if ( xObj.is() && svt::EmbeddedObjectRef::TryRunningState( xObj ) )
     285             :                         {
     286             :                             // set properties from dialog
     287           0 :                             uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
     288           0 :                             if ( xSet.is() )
     289             :                             {
     290           0 :                                 xSet->setPropertyValue("PluginURL",
     291           0 :                                         uno::makeAny( OUString( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) );
     292           0 :                             }
     293           0 :                         }
     294             :                     }
     295             :                     else
     296             :                     {
     297             :                         OSL_FAIL("Invalid URL!");
     298             :                         //! error message
     299             :                         //! can this happen???
     300           0 :                     }
     301           0 :                 }
     302             :             }
     303           0 :         }
     304             :     }
     305             : 
     306             :     //  SvInsertObjectDialog (alles in einem Dialog) wird nicht mehr benutzt
     307           0 :     if (xObj.is())
     308             :     {
     309           0 :         pView->UnmarkAll();
     310             : 
     311             :         try
     312             :         {
     313           0 :             ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
     314           0 :             Size aSize;
     315           0 :             MapMode aMap100( MAP_100TH_MM );
     316           0 :             MapUnit aMapUnit = MAP_100TH_MM;
     317             : 
     318           0 :             if ( nAspect == embed::Aspects::MSOLE_ICON )
     319             :             {
     320           0 :                 aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
     321           0 :                 aSize = aObjRef.GetSize( &aMap100 );
     322             :             }
     323             :             else
     324             :             {
     325           0 :                 awt::Size aSz;
     326             :                 try
     327             :                 {
     328           0 :                     aSz = xObj->getVisualAreaSize( nAspect );
     329             :                 }
     330           0 :                 catch( embed::NoVisualAreaSizeException& )
     331             :                 {
     332             :                     // the default size will be set later
     333             :                 }
     334             : 
     335           0 :                 aSize = Size( aSz.Width, aSz.Height );
     336             : 
     337           0 :                 aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     338           0 :                 if (aSize.Height() == 0 || aSize.Width() == 0)
     339             :                 {
     340             :                     // Rechteck mit ausgewogenem Kantenverhaeltnis
     341           0 :                     aSize.Width() = 5000;
     342           0 :                     aSize.Height() = 5000;
     343           0 :                     Size aTmp = OutputDevice::LogicToLogic( aSize, MAP_100TH_MM, aMapUnit );
     344           0 :                     aSz.Width = aTmp.Width();
     345           0 :                     aSz.Height = aTmp.Height();
     346           0 :                     xObj->setVisualAreaSize( nAspect, aSz );
     347             : 
     348             :                     //  re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
     349             :                     aSize = vcl::Window::LogicToLogic( aTmp,
     350           0 :                                     MapMode( aMapUnit ), aMap100 );
     351             :                 }
     352             :                 else
     353             :                     aSize = vcl::Window::LogicToLogic( aSize,
     354           0 :                                     MapMode( aMapUnit ), aMap100 );
     355             :             }
     356             : 
     357             :             //  Chart initialisieren ?
     358           0 :             if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
     359           0 :                 lcl_ChartInit( xObj, &pViewSh->GetViewData(), OUString() );
     360             : 
     361           0 :             ScViewData& rData = pViewSh->GetViewData();
     362             : 
     363           0 :             Point aPnt = pViewSh->GetInsertPos();
     364           0 :             if ( rData.GetDocument()->IsNegativePage( rData.GetTabNo() ) )
     365           0 :                 aPnt.X() -= aSize.Width();      // move position to left edge
     366           0 :             Rectangle aRect (aPnt, aSize);
     367           0 :             SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
     368           0 :             SdrPageView* pPV = pView->GetSdrPageView();
     369           0 :             pView->InsertObjectAtView(pObj, *pPV);
     370             : 
     371           0 :             if ( nAspect != embed::Aspects::MSOLE_ICON )
     372             :             {
     373             :                 //  Math objects change their object size during InsertObject.
     374             :                 //  New size must be set in SdrObject, or a wrong scale will be set at
     375             :                 //  ActivateObject.
     376             : 
     377             :                 try
     378             :                 {
     379           0 :                     awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     380             : 
     381           0 :                     Size aNewSize( aSz.Width, aSz.Height );
     382           0 :                     aNewSize = OutputDevice::LogicToLogic( aNewSize, aMapUnit, MAP_100TH_MM );
     383             : 
     384           0 :                     if ( aNewSize != aSize )
     385             :                     {
     386           0 :                         aRect.SetSize( aNewSize );
     387           0 :                         pObj->SetLogicRect( aRect );
     388             :                     }
     389             :                 }
     390           0 :                 catch( embed::NoVisualAreaSizeException& )
     391             :                 {}
     392             :             }
     393             : 
     394           0 :             if ( !rReq.IsAPI() )
     395             :             {
     396             :                 // XXX Activate aus Makro ist toedlich !!! ???
     397           0 :                 if (bIsFromFile)
     398             :                 {
     399             :                     // Objekt ist selektiert, also Draw-Shell aktivieren
     400           0 :                     pViewShell->SetDrawShell( true );
     401             :                 }
     402             :                 else
     403             :                 {
     404           0 :                     pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
     405             :                 }
     406             :             }
     407             : 
     408           0 :             rReq.Done();
     409             :         }
     410           0 :         catch( uno::Exception& )
     411             :         {
     412             :             OSL_FAIL( "May need error handling here!\n" );
     413             :         }
     414             :     }
     415             :     else
     416           0 :         rReq.Ignore();
     417           0 : }
     418             : 
     419           0 : void FuInsertOLE::Activate()
     420             : {
     421           0 :     FuPoor::Activate();
     422           0 : }
     423             : 
     424           0 : void FuInsertOLE::Deactivate()
     425             : {
     426           0 :     FuPoor::Deactivate();
     427           0 : }
     428             : 
     429           0 : FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
     430             :            SdrModel* pDoc, SfxRequest& rReq)
     431           0 :     : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
     432             : {
     433           0 :     const SfxItemSet*   pReqArgs    = rReq.GetArgs();
     434             : 
     435           0 :     if( ! rReq.IsAPI() )
     436           0 :         rReq.Done();
     437             : 
     438           0 :     if (!SvtModuleOptions().IsChart())
     439           0 :         return;
     440             : 
     441             :     // BM/IHA --
     442             : 
     443             :     // get range
     444           0 :     OUString aRangeString;
     445           0 :     ScRange aPositionRange;             // cell range for chart positioning
     446           0 :     ScMarkData aMark = pViewSh->GetViewData().GetMarkData();
     447           0 :     if( pReqArgs )
     448             :     {
     449             :         const SfxPoolItem* pItem;
     450           0 :         if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
     451           0 :             aRangeString = OUString( static_cast<const SfxStringItem*>(pItem)->GetValue());
     452             : 
     453           0 :         aPositionRange = pViewSh->GetViewData().GetCurPos();
     454             :     }
     455             :     else
     456             :     {
     457           0 :         bool bAutomaticMark = false;
     458           0 :         if ( !aMark.IsMarked() && !aMark.IsMultiMarked() )
     459             :         {
     460           0 :             pViewSh->GetViewData().GetView()->MarkDataArea( true );
     461           0 :             bAutomaticMark = true;
     462             :         }
     463             : 
     464           0 :         ScMarkData aMultiMark( aMark );
     465           0 :         aMultiMark.MarkToMulti();
     466             : 
     467           0 :         ScRangeList aRanges;
     468           0 :         aMultiMark.FillRangeListWithMarks( &aRanges, false );
     469           0 :         OUString aStr;
     470           0 :         ScDocument* pDocument = pViewSh->GetViewData().GetDocument();
     471           0 :         aRanges.Format( aStr, SCR_ABS_3D, pDocument, pDocument->GetAddressConvention() );
     472           0 :         aRangeString = aStr;
     473             : 
     474             :         // get "total" range for positioning
     475           0 :         if ( !aRanges.empty() )
     476             :         {
     477           0 :             aPositionRange = *aRanges[ 0 ];
     478           0 :             for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i )
     479             :             {
     480           0 :                 aPositionRange.ExtendTo( *aRanges[ i ] );
     481             :             }
     482             :         }
     483             : 
     484           0 :         if(bAutomaticMark)
     485           0 :             pViewSh->GetViewData().GetView()->Unmark();
     486             :     }
     487             : 
     488             :     // adapted old code
     489           0 :     pView->UnmarkAll();
     490             : 
     491           0 :     OUString aName;
     492           0 :     const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     493             : 
     494             :     uno::Reference < embed::XEmbeddedObject > xObj =
     495           0 :         pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName );
     496             : 
     497           0 :     uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
     498           0 :     uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
     499           0 :     if( xCompSupp.is())
     500           0 :         xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
     501             : 
     502           0 :     uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
     503           0 :     if (xChartDoc.is())
     504           0 :         xChartDoc->createDefaultChart();
     505             : 
     506             :     // lock the model to suppress any internal updates
     507           0 :     uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
     508           0 :     if( xChartModel.is() )
     509           0 :         xChartModel->lockControllers();
     510             : 
     511           0 :     ScRangeListRef aDummy;
     512           0 :     Rectangle aMarkDest;
     513             :     SCTAB nMarkTab;
     514           0 :     bool bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab );
     515             : 
     516             :     //  Objekt-Groesse
     517           0 :     awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     518           0 :     Size aSize( aSz.Width, aSz.Height );
     519             : 
     520           0 :     MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     521             : 
     522           0 :     bool bSizeCh = false;
     523           0 :     if (bDrawRect && !aMarkDest.IsEmpty())
     524             :     {
     525           0 :         aSize = aMarkDest.GetSize();
     526           0 :         bSizeCh = true;
     527             :     }
     528           0 :     if (aSize.Height() <= 0 || aSize.Width() <= 0)
     529             :     {
     530           0 :         aSize.Width() = 5000;
     531           0 :         aSize.Height() = 5000;
     532           0 :         bSizeCh = true;
     533             :     }
     534           0 :     if (bSizeCh)
     535             :     {
     536           0 :         aSize = vcl::Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
     537           0 :         aSz.Width = aSize.Width();
     538           0 :         aSz.Height = aSize.Height();
     539           0 :         xObj->setVisualAreaSize( nAspect, aSz );
     540             :     }
     541             : 
     542           0 :     ScViewData& rData = pViewSh->GetViewData();
     543           0 :     ScDocShell* pScDocSh = rData.GetDocShell();
     544           0 :     ScDocument& rScDoc   = pScDocSh->GetDocument();
     545           0 :     bool bUndo (rScDoc.IsUndoEnabled());
     546             : 
     547           0 :     if( pReqArgs )
     548             :     {
     549             :         const SfxPoolItem* pItem;
     550           0 :         sal_uInt16 nToTable = 0;
     551             : 
     552           0 :         if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
     553             :         {
     554           0 :             if ( pItem->ISA( SfxUInt16Item ) )
     555           0 :                 nToTable = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
     556           0 :             else if ( pItem->ISA( SfxBoolItem ) )
     557             :             {
     558             :                 //  in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
     559             :                 //  -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
     560             : 
     561           0 :                 if ( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
     562           0 :                     nToTable = static_cast<sal_uInt16>(rScDoc.GetTableCount());
     563             :                 else
     564           0 :                     nToTable = static_cast<sal_uInt16>(rData.GetTabNo());
     565             :             }
     566             :         }
     567             :         else
     568             :         {
     569           0 :             if (bDrawRect)
     570           0 :                 nToTable = static_cast<sal_uInt16>(nMarkTab);
     571           0 :             rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
     572             :         }
     573             : 
     574             :         // auf neue Tabelle ausgeben?
     575           0 :         if ( nToTable == rScDoc.GetTableCount() )
     576             :         {
     577             :             // dann los...
     578           0 :             OUString      aTabName;
     579           0 :             SCTAB       nNewTab = rScDoc.GetTableCount();
     580             : 
     581           0 :             rScDoc.CreateValidTabName( aTabName );
     582             : 
     583           0 :             if ( rScDoc.InsertTab( nNewTab, aTabName ) )
     584             :             {
     585           0 :                 bool bAppend = true;
     586             : 
     587           0 :                 if (bUndo)
     588             :                 {
     589           0 :                     pScDocSh->GetUndoManager()->AddUndoAction(
     590             :                         new ScUndoInsertTab( pScDocSh, nNewTab,
     591           0 :                                              bAppend, aTabName ) );
     592             :                 }
     593             : 
     594           0 :                 pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
     595           0 :                 pViewSh->SetTabNo( nNewTab, true );
     596           0 :                 pScDocSh->PostPaintExtras();            //! erst hinterher ???
     597             :             }
     598             :             else
     599             :             {
     600             :                 OSL_FAIL( "Could not create new table :-/" );
     601           0 :             }
     602             :         }
     603           0 :         else if ( nToTable != rData.GetTabNo() )
     604             :         {
     605           0 :             pViewSh->SetTabNo( nToTable, true );
     606             :         }
     607             :     }
     608             : 
     609           0 :     lcl_ChartInit( xObj, &rData, aRangeString );         // set source range, auto-detect column/row headers
     610             : 
     611             :     //  Objekt-Position
     612             : 
     613           0 :     Point aStart;
     614           0 :     if ( bDrawRect )
     615           0 :         aStart = aMarkDest.TopLeft();                       // marked by hand
     616             :     else
     617             :     {
     618             :         // get chart position (from window size and data range)
     619           0 :         aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
     620             :     }
     621             : 
     622           0 :     Rectangle aRect (aStart, aSize);
     623           0 :     SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
     624           0 :     SdrPageView* pPV = pView->GetSdrPageView();
     625             : 
     626             :     // #i121334# This call will change the chart's default background fill from white to transparent.
     627             :     // Add here again if this is wanted (see task description for details)
     628             :     // ChartHelper::AdaptDefaultsForChart( xObj );
     629             : 
     630             : //        pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
     631             : 
     632             :     // use the page instead of the view to insert, so no undo action is created yet
     633           0 :     SdrPage* pInsPage = pPV->GetPage();
     634           0 :     pInsPage->InsertObject( pObj );
     635           0 :     pView->UnmarkAllObj();
     636           0 :     pView->MarkObj( pObj, pPV );
     637           0 :     bool bAddUndo = true;               // add undo action later, unless the dialog is canceled
     638             : 
     639           0 :     if (rReq.IsAPI())
     640             :     {
     641           0 :         if( xChartModel.is() )
     642           0 :             xChartModel->unlockControllers();
     643             :     }
     644             :     else
     645             :     {
     646             :         //the controller will be unlocked by the dialog when the dialog is told to do so
     647             : 
     648             :         // only activate object if not called via API (e.g. macro)
     649           0 :         pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
     650             : 
     651             :         //open wizard
     652             :         //@todo get context from calc if that has one
     653             :         uno::Reference< uno::XComponentContext > xContext(
     654           0 :             ::cppu::defaultBootstrap_InitialComponentContext() );
     655           0 :         if(xContext.is())
     656             :         {
     657           0 :             uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
     658           0 :             if(xMCF.is())
     659             :             {
     660             :                 uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
     661           0 :                     xMCF->createInstanceWithContext(
     662             :                         OUString("com.sun.star.comp.chart2.WizardDialog")
     663           0 :                         , xContext), uno::UNO_QUERY);
     664           0 :                 uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
     665           0 :                 if( xChartModel.is() && xInit.is() )
     666             :                 {
     667           0 :                     uno::Reference< awt::XWindow > xDialogParentWindow(0);
     668             :                     //  initialize dialog
     669           0 :                     uno::Sequence<uno::Any> aSeq(2);
     670           0 :                     uno::Any* pArray = aSeq.getArray();
     671           0 :                     beans::PropertyValue aParam1;
     672           0 :                     aParam1.Name = "ParentWindow";
     673           0 :                     aParam1.Value <<= uno::makeAny(xDialogParentWindow);
     674           0 :                     beans::PropertyValue aParam2;
     675           0 :                     aParam2.Name = "ChartModel";
     676           0 :                     aParam2.Value <<= uno::makeAny(xChartModel);
     677           0 :                     pArray[0] <<= uno::makeAny(aParam1);
     678           0 :                     pArray[1] <<= uno::makeAny(aParam2);
     679           0 :                     xInit->initialize( aSeq );
     680             : 
     681             :                     // try to set the dialog's position so it doesn't hide the chart
     682           0 :                     uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
     683           0 :                     if ( xDialogProps.is() )
     684             :                     {
     685             :                         try
     686             :                         {
     687             :                             //get dialog size:
     688           0 :                             awt::Size aDialogAWTSize;
     689           0 :                             if( xDialogProps->getPropertyValue("Size")
     690           0 :                                 >>= aDialogAWTSize )
     691             :                             {
     692           0 :                                 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
     693           0 :                                 if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
     694             :                                 {
     695             :                                     //calculate and set new position
     696           0 :                                     Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect );
     697           0 :                                     xDialogProps->setPropertyValue("Position",
     698           0 :                                         uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
     699             :                                 }
     700             :                             }
     701             :                             //tell the dialog to unlock controller
     702           0 :                             xDialogProps->setPropertyValue("UnlockControllersOnExecute",
     703           0 :                                         uno::makeAny( sal_True ) );
     704             : 
     705             :                         }
     706           0 :                         catch( uno::Exception& )
     707             :                         {
     708             :                             OSL_FAIL( "Chart wizard couldn't be positioned automatically\n" );
     709             :                         }
     710             :                     }
     711             : 
     712           0 :                     sal_Int16 nDialogRet = xDialog->execute();
     713           0 :                     if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
     714             :                     {
     715             :                         // leave OLE inplace mode and unmark
     716             :                         OSL_ASSERT( pViewShell );
     717             :                         OSL_ASSERT( pView );
     718           0 :                         pViewShell->DeactivateOle();
     719           0 :                         pView->UnmarkAll();
     720             : 
     721             :                         // old page view pointer is invalid after switching sheets
     722           0 :                         pPV = pView->GetSdrPageView();
     723             : 
     724             :                         // remove the chart
     725             :                         OSL_ASSERT( pPV );
     726           0 :                         SdrPage * pPage( pPV->GetPage());
     727             :                         OSL_ASSERT( pPage );
     728             :                         OSL_ASSERT( pObj );
     729           0 :                         if( pPage )
     730             :                         {
     731             :                             // Remove the OLE2 object from the sdr page.
     732           0 :                             SdrObject* pRemoved = pPage->RemoveObject(pObj->GetOrdNum());
     733             :                             OSL_ASSERT(pRemoved == pObj);
     734           0 :                             SdrObject::Free(pRemoved); // Don't forget to free it.
     735             :                         }
     736             : 
     737           0 :                         bAddUndo = false;       // don't create the undo action for inserting
     738             : 
     739             :                         // leave the draw shell
     740           0 :                         pViewShell->SetDrawShell( false );
     741             : 
     742             :                         // reset marked cell area
     743             : 
     744           0 :                         pViewSh->GetViewData().GetViewShell()->SetMarkData(aMark);
     745             :                     }
     746             :                     else
     747             :                     {
     748             :                         OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK );
     749             :                         //@todo maybe move chart to different table
     750           0 :                     }
     751             :                 }
     752           0 :                 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
     753           0 :                 if( xComponent.is())
     754           0 :                     xComponent->dispose();
     755           0 :             }
     756           0 :         }
     757             :     }
     758             : 
     759           0 :     if ( bAddUndo )
     760             :     {
     761             :         // add undo action the same way as in SdrEditView::InsertObjectAtView
     762             :         // (using UndoActionHdl etc.)
     763           0 :         pView->AddUndo(new SdrUndoNewObj(*pObj));
     764           0 :     }
     765             : 
     766             :     // BM/IHA --
     767             : }
     768             : 
     769           0 : void FuInsertChart::Activate()
     770             : {
     771           0 :     FuPoor::Activate();
     772           0 : }
     773             : 
     774           0 : void FuInsertChart::Deactivate()
     775             : {
     776           0 :     FuPoor::Deactivate();
     777           0 : }
     778             : 
     779           0 : FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
     780             :            SdrModel* pDoc, SfxRequest& rReq, const OUString& rURL):
     781           0 :     FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
     782             : {
     783             :     uno::Reference< io::XInputStream > xStorage = comphelper::OStorageHelper::GetInputStreamFromURL(
     784           0 :             rURL, comphelper::getProcessComponentContext());
     785             : 
     786             :     comphelper::EmbeddedObjectContainer& rObjContainer =
     787           0 :         pViewShell->GetObjectShell()->GetEmbeddedObjectContainer();
     788             : 
     789           0 :     OUString aName;
     790           0 :     uno::Reference< embed::XEmbeddedObject > xObj = rObjContainer.InsertEmbeddedObject( xStorage, aName );
     791             : 
     792           0 :     const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     793           0 :     awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     794           0 :     Size aSize( aSz.Width, aSz.Height );
     795             : 
     796           0 :     ScRange aPositionRange = pViewSh->GetViewData().GetCurPos();
     797           0 :     Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
     798           0 :     Rectangle aRect (aStart, aSize);
     799           0 :     SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
     800             : 
     801           0 :     SdrPageView* pPV = pView->GetSdrPageView();
     802             : 
     803             :     // use the page instead of the view to insert, so no undo action is created yet
     804           0 :     SdrPage* pInsPage = pPV->GetPage();
     805           0 :     pInsPage->InsertObject( pObj );
     806           0 :     pView->UnmarkAllObj();
     807           0 :     pView->MarkObj( pObj, pPV );
     808             : 
     809           0 :     pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
     810           0 : }
     811             : 
     812           0 : void FuInsertChartFromFile::Activate()
     813             : {
     814           0 :     FuPoor::Activate();
     815           0 : }
     816             : 
     817           0 : void FuInsertChartFromFile::Deactivate()
     818             : {
     819           0 :     FuPoor::Deactivate();
     820         228 : }
     821             : 
     822             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10