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

Generated by: LCOV version 1.10