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