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