LCOV - code coverage report
Current view: top level - sc/source/ui/drawfunc - fuins2.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 375 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
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 <svl/urihelper.hxx>
      35             : #include <unotools/moduleoptions.hxx>
      36             : #include <svtools/insdlg.hxx>
      37             : #include <svtools/soerr.hxx>
      38             : #include <svx/svxdlg.hxx>
      39             : #include <comphelper/classids.hxx>
      40             : #include <svx/svdpagv.hxx>
      41             : #include <svx/svdpage.hxx>
      42             : #include <svx/svdundo.hxx>
      43             : #include <sfx2/msgpool.hxx>
      44             : #include <svx/charthelper.hxx>
      45             : #include <scmod.hxx>
      46             : 
      47             : // BM/IHA --
      48             : #include <cppuhelper/component_context.hxx>
      49             : #include <comphelper/processfactory.hxx>
      50             : #include <comphelper/storagehelper.hxx>
      51             : #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
      52             : #include <com/sun/star/frame/XComponentLoader.hpp>
      53             : #include <com/sun/star/beans/PropertyValue.hpp>
      54             : #include <com/sun/star/chart2/data/XDataProvider.hpp>
      55             : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
      56             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      57             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      58             : #include <com/sun/star/lang/XInitialization.hpp>
      59             : #include <com/sun/star/frame/XModel.hpp>
      60             : #include <com/sun/star/chart/ChartDataRowSource.hpp>
      61             : #include <cppuhelper/bootstrap.hxx>
      62             : 
      63             : using namespace ::com::sun::star;
      64             : // BM/IHA --
      65             : 
      66             : // erAck
      67             : #include "chart2uno.hxx"
      68             : // erAck
      69             : 
      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             : 
      83             : namespace {
      84             : 
      85           0 : void lcl_ChartInit( const uno::Reference < embed::XEmbeddedObject >& xObj, ScViewData* pViewData,
      86             :                     const OUString& rRangeParam )
      87             : {
      88           0 :     ScDocShell* pDocShell = pViewData->GetDocShell();
      89           0 :     ScDocument* pScDoc = pDocShell->GetDocument();
      90             : 
      91           0 :     OUString aRangeString( rRangeParam );
      92           0 :     if ( aRangeString.isEmpty() )
      93             :     {
      94           0 :         SCCOL nCol1 = 0;
      95           0 :         SCROW nRow1 = 0;
      96           0 :         SCTAB nTab1 = 0;
      97           0 :         SCCOL nCol2 = 0;
      98           0 :         SCROW nRow2 = 0;
      99           0 :         SCTAB nTab2 = 0;
     100             : 
     101           0 :         ScMarkData& rMark = pViewData->GetMarkData();
     102           0 :         if ( !rMark.IsMarked() )
     103           0 :             pViewData->GetView()->MarkDataArea( true );
     104             : 
     105           0 :         if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
     106             :         {
     107           0 :             PutInOrder( nCol1, nCol2 );
     108           0 :             PutInOrder( nRow1, nRow2 );
     109           0 :             if ( nCol2>nCol1 || nRow2>nRow1 )
     110             :             {
     111           0 :                 ScDocument* pDoc = pViewData->GetDocument();
     112           0 :                 pDoc->LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
     113             : 
     114           0 :                 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
     115           0 :                 aRangeString = aRange.Format(SCR_ABS_3D, pScDoc);
     116             :             }
     117             :         }
     118             :     }
     119             : 
     120           0 :     if ( !aRangeString.isEmpty() )
     121             :     {
     122             :         // connect to Calc data (if no range string, leave chart alone, with its own data)
     123             : 
     124           0 :         uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
     125           0 :         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
     126           0 :         if( xCompSupp.is())
     127           0 :             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
     128             :         OSL_ASSERT( xReceiver.is());
     129           0 :         if( xReceiver.is() )
     130             :         {
     131           0 :             uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( pScDoc );
     132           0 :             xReceiver->attachDataProvider( xDataProvider );
     133             : 
     134           0 :             uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
     135           0 :             xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
     136             : 
     137             :             // Same behavior as with old chart: Always assume data series in columns
     138           0 :             chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
     139           0 :             bool bHasCategories = false;
     140           0 :             bool bFirstCellAsLabel = false;
     141             : 
     142             :             // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
     143           0 :             ScRangeListRef aRangeListRef( new ScRangeList );
     144           0 :             aRangeListRef->Parse( aRangeString, pScDoc, SCA_VALID, pScDoc->GetAddressConvention() );
     145           0 :             if ( !aRangeListRef->empty() )
     146             :             {
     147           0 :                 pScDoc->LimitChartIfAll( aRangeListRef );               // limit whole columns/rows to used area
     148             : 
     149             :                 // update string from modified ranges.  The ranges must be in the current formula syntax.
     150           0 :                 OUString aTmpStr;
     151           0 :                 aRangeListRef->Format( aTmpStr, SCR_ABS_3D, pScDoc, pScDoc->GetAddressConvention() );
     152           0 :                 aRangeString = aTmpStr;
     153             : 
     154           0 :                 ScChartPositioner aChartPositioner( pScDoc, aRangeListRef );
     155           0 :                 const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
     156           0 :                 if( pPositionMap )
     157             :                 {
     158           0 :                     SCSIZE nRowCount = pPositionMap->GetRowCount();
     159           0 :                     if( 1==nRowCount )
     160           0 :                         eDataRowSource = chart::ChartDataRowSource_ROWS;
     161             :                 }
     162           0 :                 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
     163             :                 {
     164           0 :                     bHasCategories = aChartPositioner.HasRowHeaders();
     165           0 :                     bFirstCellAsLabel = aChartPositioner.HasColHeaders();
     166             :                 }
     167             :                 else    // in case the default is changed
     168             :                 {
     169           0 :                     bHasCategories = aChartPositioner.HasColHeaders();
     170           0 :                     bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
     171           0 :                 }
     172             :             }
     173             : 
     174           0 :             uno::Sequence< beans::PropertyValue > aArgs( 4 );
     175           0 :             aArgs[0] = beans::PropertyValue(
     176             :                 OUString("CellRangeRepresentation"), -1,
     177           0 :                 uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
     178           0 :             aArgs[1] = beans::PropertyValue(
     179             :                 OUString("HasCategories"), -1,
     180           0 :                 uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
     181           0 :             aArgs[2] = beans::PropertyValue(
     182             :                 OUString("FirstCellAsLabel"), -1,
     183           0 :                 uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
     184           0 :             aArgs[3] = beans::PropertyValue(
     185             :                 OUString("DataRowSource"), -1,
     186           0 :                 uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
     187           0 :             xReceiver->setArguments( aArgs );
     188             : 
     189             :             // don't create chart listener here (range may be modified in chart dialog)
     190           0 :         }
     191           0 :     }
     192           0 : }
     193             : 
     194             : }
     195             : 
     196           0 : FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
     197             :            SdrModel* pDoc, SfxRequest& rReq)
     198           0 :     : FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
     199             : {
     200           0 :     if( ! rReq.IsAPI() )
     201           0 :         rReq.Done();
     202             : 
     203             :     //! hier DLL's initalisieren, damit die Factories existieren?
     204             : 
     205           0 :     uno::Reference < embed::XEmbeddedObject > xObj;
     206           0 :     uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
     207           0 :     sal_Bool bIsFromFile = false;
     208           0 :     OUString aName;
     209             : 
     210           0 :     sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     211           0 :     OUString aIconMediaType;
     212           0 :     uno::Reference< io::XInputStream > xIconMetaFile;
     213             : 
     214             : 
     215           0 :     sal_uInt16 nSlot = rReq.GetSlot();
     216           0 :     SFX_REQUEST_ARG( rReq, pNameItem, SfxGlobalNameItem, SID_INSERT_OBJECT, false );
     217           0 :     if ( nSlot == SID_INSERT_OBJECT && pNameItem )
     218             :     {
     219           0 :         SvGlobalName aClassName = pNameItem->GetValue();
     220           0 :         xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( aClassName.GetByteSequence(), aName );
     221             :     }
     222           0 :     else if ( nSlot == SID_INSERT_SMATH )
     223             :     {
     224           0 :         if ( SvtModuleOptions().IsMath() )
     225             :         {
     226           0 :             nSlot = SID_INSERT_OBJECT;
     227           0 :             xObj = pViewShell->GetViewFrame()->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SM_CLASSID_60 ).GetByteSequence(), aName );
     228           0 :             rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
     229             :         }
     230             :     }
     231             :     else
     232             :     {
     233           0 :         SvObjectServerList aServerLst;
     234           0 :         switch ( nSlot )
     235             :         {
     236             :             case SID_INSERT_OBJECT :
     237           0 :                 aServerLst.FillInsertObjects();
     238           0 :                 aServerLst.Remove( ScDocShell::Factory().GetClassId() );   // Starcalc nicht anzeigen
     239             :                 //TODO/LATER: currently no inserting of ClassId into SfxRequest!
     240             :             case SID_INSERT_PLUGIN :
     241             :             case SID_INSERT_FLOATINGFRAME :
     242             :             {
     243           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     244             :                 SfxAbstractInsertObjectDialog* pDlg =
     245           0 :                         pFact->CreateInsertObjectDialog( pViewShell->GetWindow(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
     246           0 :                         xStorage, &aServerLst );
     247           0 :                 if ( pDlg )
     248             :                 {
     249           0 :                     pDlg->Execute();
     250           0 :                     xObj = pDlg->GetObject();
     251             : 
     252           0 :                     xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
     253           0 :                     if ( xIconMetaFile.is() )
     254           0 :                         nAspect = embed::Aspects::MSOLE_ICON;
     255             : 
     256           0 :                     if ( xObj.is() )
     257           0 :                         pViewSh->GetObjectShell()->GetEmbeddedObjectContainer().InsertEmbeddedObject( xObj, aName );
     258             :                     // damit DrawShell eingeschaltet wird (Objekt aktivieren ist unnoetig):
     259           0 :                     bIsFromFile = !pDlg->IsCreateNew();
     260           0 :                     DELETEZ( pDlg );
     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 = Window::LogicToLogic( aTmp,
     350           0 :                                     MapMode( aMapUnit ), aMap100 );
     351             :                 }
     352             :                 else
     353             :                     aSize = 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* pData = pViewSh->GetViewData();
     362             : 
     363           0 :             Point aPnt = pViewSh->GetInsertPos();
     364           0 :             if ( pData->GetDocument()->IsNegativePage( pData->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, 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             :     {
     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( ((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             : 
     489             :         // adapted old code
     490           0 :         pView->UnmarkAll();
     491             : 
     492           0 :         OUString aName;
     493           0 :         const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     494             : 
     495             :         uno::Reference < embed::XEmbeddedObject > xObj =
     496           0 :             pViewShell->GetObjectShell()->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID_60 ).GetByteSequence(), aName );
     497             : 
     498           0 :         uno::Reference< ::com::sun::star::chart2::data::XDataReceiver > xReceiver;
     499           0 :         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
     500           0 :         if( xCompSupp.is())
     501           0 :             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
     502             : 
     503             :         // lock the model to suppress any internal updates
     504           0 :         uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
     505           0 :         if( xChartModel.is() )
     506           0 :             xChartModel->lockControllers();
     507             : 
     508           0 :         ScRangeListRef aDummy;
     509           0 :         Rectangle aMarkDest;
     510             :         SCTAB nMarkTab;
     511           0 :         sal_Bool bDrawRect = pViewShell->GetChartArea( aDummy, aMarkDest, nMarkTab );
     512             : 
     513             :         //  Objekt-Groesse
     514           0 :         awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     515           0 :         Size aSize( aSz.Width, aSz.Height );
     516             : 
     517           0 :         MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
     518             : 
     519           0 :         sal_Bool bSizeCh = false;
     520           0 :         if (bDrawRect && !aMarkDest.IsEmpty())
     521             :         {
     522           0 :             aSize = aMarkDest.GetSize();
     523           0 :             bSizeCh = sal_True;
     524             :         }
     525           0 :         if (aSize.Height() <= 0 || aSize.Width() <= 0)
     526             :         {
     527           0 :             aSize.Width() = 5000;
     528           0 :             aSize.Height() = 5000;
     529           0 :             bSizeCh = sal_True;
     530             :         }
     531           0 :         if (bSizeCh)
     532             :         {
     533           0 :             aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
     534           0 :             aSz.Width = aSize.Width();
     535           0 :             aSz.Height = aSize.Height();
     536           0 :             xObj->setVisualAreaSize( nAspect, aSz );
     537             :         }
     538             : 
     539           0 :         ScViewData* pData = pViewSh->GetViewData();
     540           0 :         ScDocShell* pScDocSh = pData->GetDocShell();
     541           0 :         ScDocument* pScDoc   = pScDocSh->GetDocument();
     542           0 :         sal_Bool bUndo (pScDoc->IsUndoEnabled());
     543             : 
     544           0 :         if( pReqArgs )
     545             :         {
     546             :             const SfxPoolItem* pItem;
     547           0 :             sal_uInt16 nToTable = 0;
     548             : 
     549           0 :             if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
     550             :             {
     551           0 :                 if ( pItem->ISA( SfxUInt16Item ) )
     552           0 :                     nToTable = ((const SfxUInt16Item*)pItem)->GetValue();
     553           0 :                 else if ( pItem->ISA( SfxBoolItem ) )
     554             :                 {
     555             :                     //  in der idl fuer Basic steht FN_PARAM_4 als SfxBoolItem
     556             :                     //  -> wenn gesetzt, neue Tabelle, sonst aktuelle Tabelle
     557             : 
     558           0 :                     if ( ((const SfxBoolItem*)pItem)->GetValue() )
     559           0 :                         nToTable = static_cast<sal_uInt16>(pScDoc->GetTableCount());
     560             :                     else
     561           0 :                         nToTable = static_cast<sal_uInt16>(pData->GetTabNo());
     562             :                 }
     563             :             }
     564             :             else
     565             :             {
     566           0 :                 if (bDrawRect)
     567           0 :                     nToTable = static_cast<sal_uInt16>(nMarkTab);
     568           0 :                 rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
     569             :             }
     570             : 
     571             :             // auf neue Tabelle ausgeben?
     572           0 :             if ( nToTable == pScDoc->GetTableCount() )
     573             :             {
     574             :                 // dann los...
     575           0 :                 OUString      aTabName;
     576           0 :                 SCTAB       nNewTab = pScDoc->GetTableCount();
     577             : 
     578           0 :                 pScDoc->CreateValidTabName( aTabName );
     579             : 
     580           0 :                 if ( pScDoc->InsertTab( nNewTab, aTabName ) )
     581             :                 {
     582           0 :                     sal_Bool bAppend = sal_True;
     583             : 
     584           0 :                     if (bUndo)
     585             :                     {
     586           0 :                         pScDocSh->GetUndoManager()->AddUndoAction(
     587             :                             new ScUndoInsertTab( pScDocSh, nNewTab,
     588           0 :                                                  bAppend, aTabName ) );
     589             :                     }
     590             : 
     591           0 :                     pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
     592           0 :                     pViewSh->SetTabNo( nNewTab, true );
     593           0 :                     pScDocSh->PostPaintExtras();            //! erst hinterher ???
     594             :                 }
     595             :                 else
     596             :                 {
     597             :                     OSL_FAIL( "Could not create new table :-/" );
     598           0 :                 }
     599             :             }
     600           0 :             else if ( nToTable != pData->GetTabNo() )
     601             :             {
     602           0 :                 pViewSh->SetTabNo( nToTable, true );
     603             :             }
     604             :         }
     605             : 
     606           0 :         lcl_ChartInit( xObj, pData, aRangeString );         // set source range, auto-detect column/row headers
     607             : 
     608             :         //  Objekt-Position
     609             : 
     610           0 :         Point aStart;
     611           0 :         if ( bDrawRect )
     612           0 :             aStart = aMarkDest.TopLeft();                       // marked by hand
     613             :         else
     614             :         {
     615             :             // get chart position (from window size and data range)
     616           0 :             aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
     617             :         }
     618             : 
     619           0 :         Rectangle aRect (aStart, aSize);
     620           0 :         SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
     621           0 :         SdrPageView* pPV = pView->GetSdrPageView();
     622             : 
     623             :         // #i121334# This call will change the chart's default background fill from white to transparent.
     624             :         // Add here again if this is wanted (see task description for details)
     625             :         // ChartHelper::AdaptDefaultsForChart( xObj );
     626             : 
     627             : //        pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immidiate redraw and asks the chart for a visual representation
     628             : 
     629             :         // use the page instead of the view to insert, so no undo action is created yet
     630           0 :         SdrPage* pInsPage = pPV->GetPage();
     631           0 :         pInsPage->InsertObject( pObj );
     632           0 :         pView->UnmarkAllObj();
     633           0 :         pView->MarkObj( pObj, pPV );
     634           0 :         bool bAddUndo = true;               // add undo action later, unless the dialog is canceled
     635             : 
     636           0 :         if (rReq.IsAPI())
     637             :         {
     638           0 :             if( xChartModel.is() )
     639           0 :                 xChartModel->unlockControllers();
     640             :         }
     641             :         else
     642             :         {
     643             :             //the controller will be unlocked by the dialog when the dialog is told to do so
     644             : 
     645             :             // only activate object if not called via API (e.g. macro)
     646           0 :             pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
     647             : 
     648             :             //open wizard
     649             :             //@todo get context from calc if that has one
     650             :             uno::Reference< uno::XComponentContext > xContext(
     651           0 :                 ::cppu::defaultBootstrap_InitialComponentContext() );
     652           0 :             if(xContext.is())
     653             :             {
     654           0 :                 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
     655           0 :                 if(xMCF.is())
     656             :                 {
     657             :                     uno::Reference< ui::dialogs::XExecutableDialog > xDialog(
     658           0 :                         xMCF->createInstanceWithContext(
     659             :                             OUString("com.sun.star.comp.chart2.WizardDialog")
     660           0 :                             , xContext), uno::UNO_QUERY);
     661           0 :                     uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
     662           0 :                     if( xChartModel.is() && xInit.is() )
     663             :                     {
     664           0 :                         uno::Reference< awt::XWindow > xDialogParentWindow(0);
     665             :                         //  initialize dialog
     666           0 :                         uno::Sequence<uno::Any> aSeq(2);
     667           0 :                         uno::Any* pArray = aSeq.getArray();
     668           0 :                         beans::PropertyValue aParam1;
     669           0 :                         aParam1.Name = "ParentWindow";
     670           0 :                         aParam1.Value <<= uno::makeAny(xDialogParentWindow);
     671           0 :                         beans::PropertyValue aParam2;
     672           0 :                         aParam2.Name = "ChartModel";
     673           0 :                         aParam2.Value <<= uno::makeAny(xChartModel);
     674           0 :                         pArray[0] <<= uno::makeAny(aParam1);
     675           0 :                         pArray[1] <<= uno::makeAny(aParam2);
     676           0 :                         xInit->initialize( aSeq );
     677             : 
     678             :                         // try to set the dialog's position so it doesn't hide the chart
     679           0 :                         uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
     680           0 :                         if ( xDialogProps.is() )
     681             :                         {
     682             :                             try
     683             :                             {
     684             :                                 //get dialog size:
     685           0 :                                 awt::Size aDialogAWTSize;
     686           0 :                                 if( xDialogProps->getPropertyValue("Size")
     687           0 :                                     >>= aDialogAWTSize )
     688             :                                 {
     689           0 :                                     Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
     690           0 :                                     if ( aDialogSize.Width() > 0 && aDialogSize.Height() > 0 )
     691             :                                     {
     692             :                                         //calculate and set new position
     693           0 :                                         Point aDialogPos = pViewShell->GetChartDialogPos( aDialogSize, aRect );
     694           0 :                                         xDialogProps->setPropertyValue("Position",
     695           0 :                                             uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
     696             :                                     }
     697             :                                 }
     698             :                                 //tell the dialog to unlock controller
     699           0 :                                 xDialogProps->setPropertyValue("UnlockControllersOnExecute",
     700           0 :                                             uno::makeAny( sal_True ) );
     701             : 
     702             :                             }
     703           0 :                             catch( uno::Exception& )
     704             :                             {
     705             :                                 OSL_FAIL( "Chart wizard couldn't be positioned automatically\n" );
     706             :                             }
     707             :                         }
     708             : 
     709           0 :                         sal_Int16 nDialogRet = xDialog->execute();
     710           0 :                         if( nDialogRet == ui::dialogs::ExecutableDialogResults::CANCEL )
     711             :                         {
     712             :                             // leave OLE inplace mode and unmark
     713             :                             OSL_ASSERT( pViewShell );
     714             :                             OSL_ASSERT( pView );
     715           0 :                             pViewShell->DeactivateOle();
     716           0 :                             pView->UnmarkAll();
     717             : 
     718             :                             // old page view pointer is invalid after switching sheets
     719           0 :                             pPV = pView->GetSdrPageView();
     720             : 
     721             :                             // remove the chart
     722             :                             OSL_ASSERT( pPV );
     723           0 :                             SdrPage * pPage( pPV->GetPage());
     724             :                             OSL_ASSERT( pPage );
     725             :                             OSL_ASSERT( pObj );
     726           0 :                             if( pPage )
     727           0 :                                 pPage->RemoveObject( pObj->GetOrdNum());
     728             : 
     729           0 :                             bAddUndo = false;       // don't create the undo action for inserting
     730             : 
     731             :                             // leave the draw shell
     732           0 :                             pViewShell->SetDrawShell( false );
     733             : 
     734             :                             // reset marked cell area
     735             : 
     736           0 :                             pViewSh->GetViewData()->GetViewShell()->SetMarkData(aMark);
     737             :                         }
     738             :                         else
     739             :                         {
     740             :                             OSL_ASSERT( nDialogRet == ui::dialogs::ExecutableDialogResults::OK );
     741             :                             //@todo maybe move chart to different table
     742           0 :                         }
     743             :                     }
     744           0 :                     uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
     745           0 :                     if( xComponent.is())
     746           0 :                         xComponent->dispose();
     747           0 :                 }
     748           0 :             }
     749             :         }
     750             : 
     751           0 :         if ( bAddUndo )
     752             :         {
     753             :             // add undo action the same way as in SdrEditView::InsertObjectAtView
     754             :             // (using UndoActionHdl etc.)
     755           0 :             pView->AddUndo(pDoc->GetSdrUndoFactory().CreateUndoNewObject(*pObj));
     756           0 :         }
     757             : 
     758             :         // BM/IHA --
     759             :     }
     760           0 : }
     761             : 
     762           0 : void FuInsertChart::Activate()
     763             : {
     764           0 :     FuPoor::Activate();
     765           0 : }
     766             : 
     767           0 : void FuInsertChart::Deactivate()
     768             : {
     769           0 :     FuPoor::Deactivate();
     770           0 : }
     771             : 
     772           0 : FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
     773             :            SdrModel* pDoc, SfxRequest& rReq, const OUString& rURL):
     774           0 :     FuPoor(pViewSh, pWin, pViewP, pDoc, rReq)
     775             : {
     776             :     uno::Reference< io::XInputStream > xStorage = comphelper::OStorageHelper::GetInputStreamFromURL(
     777           0 :             rURL, comphelper::getProcessComponentContext());
     778             : 
     779             :     comphelper::EmbeddedObjectContainer& rObjContainer =
     780           0 :         pViewShell->GetObjectShell()->GetEmbeddedObjectContainer();
     781             : 
     782           0 :     OUString aName;
     783           0 :     uno::Reference< embed::XEmbeddedObject > xObj = rObjContainer.InsertEmbeddedObject( xStorage, aName );
     784             : 
     785           0 :     const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
     786           0 :     awt::Size aSz = xObj->getVisualAreaSize( nAspect );
     787           0 :     Size aSize( aSz.Width, aSz.Height );
     788             : 
     789           0 :     ScRange aPositionRange = pViewSh->GetViewData()->GetCurPos();
     790           0 :     Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
     791           0 :     Rectangle aRect (aStart, aSize);
     792           0 :     SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
     793             : 
     794           0 :     SdrPageView* pPV = pView->GetSdrPageView();
     795             : 
     796             :     // use the page instead of the view to insert, so no undo action is created yet
     797           0 :     SdrPage* pInsPage = pPV->GetPage();
     798           0 :     pInsPage->InsertObject( pObj );
     799           0 :     pView->UnmarkAllObj();
     800           0 :     pView->MarkObj( pObj, pPV );
     801             : 
     802           0 :     pViewShell->ActivateObject( (SdrOle2Obj*) pObj, SVVERB_SHOW );
     803           0 : }
     804             : 
     805           0 : void FuInsertChartFromFile::Activate()
     806             : {
     807           0 :     FuPoor::Activate();
     808           0 : }
     809             : 
     810           0 : void FuInsertChartFromFile::Deactivate()
     811             : {
     812           0 :     FuPoor::Deactivate();
     813           0 : }
     814             : 
     815             : 
     816             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10