LibreOffice Module sc (master)  1
fuins2.cxx
Go to the documentation of this file.
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/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 
27 #include <sot/exchange.hxx>
28 #include <svl/globalnameitem.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svl/stritem.hxx>
31 #include <svx/svdoole2.hxx>
33 #include <svtools/insdlg.hxx>
34 #include <svtools/embedhlp.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <comphelper/classids.hxx>
37 #include <svx/svdpagv.hxx>
38 #include <svx/svdpage.hxx>
39 #include <svx/svdundo.hxx>
40 #include <sfx2/msgpool.hxx>
41 #include <sfx2/msg.hxx>
42 #include <scmod.hxx>
43 #include <sal/log.hxx>
44 #include <tools/diagnose_ex.h>
45 
46 #include <comphelper/lok.hxx>
49 #include <sfx2/lokhelper.hxx>
50 #include <com/sun/star/embed/EmbedVerbs.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
53 #include <com/sun/star/chart2/XChartDocument.hpp>
54 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
55 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
56 #include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
57 #include <com/sun/star/lang/XInitialization.hpp>
58 #include <com/sun/star/frame/XModel.hpp>
59 #include <com/sun/star/chart/ChartDataRowSource.hpp>
60 #include <cppuhelper/bootstrap.hxx>
62 
64 #include <chart2uno.hxx>
65 #include <fuinsert.hxx>
66 #include <tabvwsh.hxx>
67 #include <sc.hrc>
68 #include <chartpos.hxx>
69 #include <docsh.hxx>
70 #include <document.hxx>
71 #include <undotab.hxx>
72 #include <uiitems.hxx>
73 #include <drawview.hxx>
74 #include <markdata.hxx>
75 #include <dpobject.hxx>
76 #include <memory>
77 
78 using namespace css;
79 
80 namespace
81 {
82 
83 void lcl_ChartInit(const uno::Reference <embed::XEmbeddedObject>& xObj, ScViewData* pViewData,
84  const OUString& rRangeParam, bool bRangeIsPivotTable)
85 {
86  ScDocShell* pDocShell = pViewData->GetDocShell();
87  ScDocument& rScDoc = pDocShell->GetDocument();
88 
89  OUString aRangeString(rRangeParam);
90 
91  if (aRangeString.isEmpty() && !bRangeIsPivotTable)
92  {
93  SCCOL nCol1 = 0;
94  SCROW nRow1 = 0;
95  SCTAB nTab1 = 0;
96  SCCOL nCol2 = 0;
97  SCROW nRow2 = 0;
98  SCTAB nTab2 = 0;
99 
100  ScMarkData& rMark = pViewData->GetMarkData();
101  if ( !rMark.IsMarked() )
102  pViewData->GetView()->MarkDataArea();
103 
104  if ( pViewData->GetSimpleArea( nCol1,nRow1,nTab1, nCol2,nRow2,nTab2 ) == SC_MARK_SIMPLE )
105  {
106  PutInOrder( nCol1, nCol2 );
107  PutInOrder( nRow1, nRow2 );
108  if (nCol2 >= nCol1 || nRow2 >= nRow1)
109  {
110  ScDocument& rDoc = pViewData->GetDocument();
111  rDoc.LimitChartArea( nTab1, nCol1,nRow1, nCol2,nRow2 );
112 
113  ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
114  aRangeString = aRange.Format(rScDoc, ScRefFlags::RANGE_ABS_3D, rScDoc.GetAddressConvention());
115  }
116  }
117  }
118 
119  if (aRangeString.isEmpty())
120  return;
121 
122  // connect to Calc data (if no range string, leave chart alone, with its own data)
123 
124  uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
125  if( xObj.is())
126  xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
127  OSL_ASSERT( xReceiver.is());
128  if( !xReceiver.is() )
129  return;
130 
131  uno::Reference<chart2::data::XDataProvider> xDataProvider;
132  if (bRangeIsPivotTable)
133  {
134  std::unique_ptr<sc::PivotTableDataProvider> pPivotTableDataProvider(new sc::PivotTableDataProvider(rScDoc));
135  pPivotTableDataProvider->setPivotTableName(aRangeString);
136  xDataProvider.set(pPivotTableDataProvider.release());
137  }
138  else
139  {
140  xDataProvider.set(new ScChart2DataProvider(&rScDoc));
141  }
142 
143  xReceiver->attachDataProvider(xDataProvider);
144 
145  uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
146  xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
147 
148  // Same behavior as with old chart: Always assume data series in columns
149  chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
150  bool bHasCategories = false;
151  bool bFirstCellAsLabel = false;
152 
153  // use ScChartPositioner to auto-detect column/row headers (like ScChartArray in old version)
154  ScRangeListRef aRangeListRef( new ScRangeList );
155  aRangeListRef->Parse( aRangeString, rScDoc, rScDoc.GetAddressConvention() );
156  if ( !aRangeListRef->empty() )
157  {
158  rScDoc.LimitChartIfAll( aRangeListRef ); // limit whole columns/rows to used area
159 
160  // update string from modified ranges. The ranges must be in the current formula syntax.
161  OUString aTmpStr;
162  aRangeListRef->Format( aTmpStr, ScRefFlags::RANGE_ABS_3D, rScDoc, rScDoc.GetAddressConvention() );
163  aRangeString = aTmpStr;
164 
165  ScChartPositioner aChartPositioner( rScDoc, aRangeListRef );
166  const ScChartPositionMap* pPositionMap( aChartPositioner.GetPositionMap() );
167  if( pPositionMap )
168  {
169  SCSIZE nRowCount = pPositionMap->GetRowCount();
170  if( 1==nRowCount )
171  eDataRowSource = chart::ChartDataRowSource_ROWS;
172  }
173  if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
174  {
175  bHasCategories = aChartPositioner.HasRowHeaders();
176  bFirstCellAsLabel = aChartPositioner.HasColHeaders();
177  }
178  else // in case the default is changed
179  {
180  bHasCategories = aChartPositioner.HasColHeaders();
181  bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
182  }
183  }
184 
185  uno::Sequence< beans::PropertyValue > aArgs( 4 );
186  aArgs[0] = beans::PropertyValue(
187  "CellRangeRepresentation", -1,
188  uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
189  aArgs[1] = beans::PropertyValue(
190  "HasCategories", -1,
191  uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
192  aArgs[2] = beans::PropertyValue(
193  "FirstCellAsLabel", -1,
194  uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
195  aArgs[3] = beans::PropertyValue(
196  "DataRowSource", -1,
197  uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
198 
199  try
200  {
201  xReceiver->setArguments( aArgs );
202  }
203  catch (const lang::IllegalArgumentException&)
204  {
205  // Can happen for invalid aRangeString, in which case a Chart
206  // will be created nevertheless and the range string can be
207  // edited.
208  TOOLS_WARN_EXCEPTION("sc.ui",
209  "lcl_ChartInit - caught IllegalArgumentException might be due to aRangeString: " << aRangeString);
210  }
211 
212  // don't create chart listener here (range may be modified in chart dialog)
213 }
214 
215 }
216 
218  SdrModel* pDoc, SfxRequest& rReq)
219  : FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
220 {
221  if( ! rReq.IsAPI() )
222  rReq.Done();
223 
225 
226  uno::Reference < embed::XEmbeddedObject > xObj;
227  uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
228  bool bIsFromFile = false;
229  OUString aName;
230 
231  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
232  OUString aIconMediaType;
233  uno::Reference< io::XInputStream > xIconMetaFile;
234 
235  const sal_uInt16 nSlot = rReq.GetSlot();
236  const SfxGlobalNameItem* pNameItem = rReq.GetArg<SfxGlobalNameItem>(SID_INSERT_OBJECT);
237  if ( nSlot == SID_INSERT_OBJECT && pNameItem )
238  {
239  const SvGlobalName& aClassName = pNameItem->GetValue();
241  }
242  else if ( nSlot == SID_INSERT_SMATH )
243  {
244  if ( SvtModuleOptions().IsMath() )
245  {
247  rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
248  }
249  }
250  else
251  {
252  SvObjectServerList aServerLst;
253  switch ( nSlot )
254  {
255  case SID_INSERT_OBJECT :
256  aServerLst.FillInsertObjects();
257  aServerLst.Remove( ScDocShell::Factory().GetClassId() ); // Do not show Starcalc
258  //TODO/LATER: currently no inserting of ClassId into SfxRequest!
259  [[fallthrough]]; //TODO ???
260  case SID_INSERT_FLOATINGFRAME :
261  {
264  pFact->CreateInsertObjectDialog( rViewShell.GetFrameWeld(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
265  xStorage, &aServerLst ));
266  if ( pDlg )
267  {
268  pDlg->Execute();
269  xObj = pDlg->GetObject();
270 
271  xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
272  if ( xIconMetaFile.is() )
273  nAspect = embed::Aspects::MSOLE_ICON;
274 
275  if ( xObj.is() )
277  // to activate DrawShell (no need to activate Object)
278  bIsFromFile = !pDlg->IsCreateNew();
279  }
280 
281  break;
282  }
283  }
284  }
285 
286  // SvInsertObjectDialog (everything in one Dialog) are not used anymore
287  if (xObj.is())
288  {
289  pView->UnmarkAll();
290 
291  try
292  {
293  ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
294  Size aSize;
295  MapMode aMap100( MapUnit::Map100thMM );
296  MapUnit aMapUnit = MapUnit::Map100thMM;
297 
298  if ( nAspect == embed::Aspects::MSOLE_ICON )
299  {
300  aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
301  aSize = aObjRef.GetSize( &aMap100 );
302  }
303  else
304  {
305  awt::Size aSz;
306  try
307  {
308  aSz = xObj->getVisualAreaSize( nAspect );
309  }
310  catch( embed::NoVisualAreaSizeException& )
311  {
312  // the default size will be set later
313  }
314 
315  aSize = Size( aSz.Width, aSz.Height );
316 
317  aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
318  if (aSize.IsEmpty())
319  {
320  // rectangle with balanced edge ratio
321  aSize.setWidth( 5000 );
322  aSize.setHeight( 5000 );
323  Size aTmp = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(aMapUnit));
324  aSz.Width = aTmp.Width();
325  aSz.Height = aTmp.Height();
326  xObj->setVisualAreaSize( nAspect, aSz );
327 
328  // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
329  aSize = vcl::Window::LogicToLogic( aTmp,
330  MapMode( aMapUnit ), aMap100 );
331  }
332  else
333  aSize = vcl::Window::LogicToLogic( aSize,
334  MapMode( aMapUnit ), aMap100 );
335  }
336 
337  // initialize chart ?
338  if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
339  lcl_ChartInit(xObj, &rViewSh.GetViewData(), OUString(), false);
340 
341  ScViewData& rData = rViewSh.GetViewData();
342 
343  Point aPnt = rViewSh.GetInsertPos();
344  if ( rData.GetDocument().IsNegativePage( rData.GetTabNo() ) )
345  aPnt.AdjustX( -(aSize.Width()) ); // move position to left edge
346  tools::Rectangle aRect (aPnt, aSize);
347  SdrOle2Obj* pObj = new SdrOle2Obj(
348  *pDoc, // TTTT should be reference
349  aObjRef,
350  aName,
351  aRect);
352  SdrPageView* pPV = pView->GetSdrPageView();
353  bool bSuccess = pView->InsertObjectAtView(pObj, *pPV);
354 
355  if (bSuccess && nAspect != embed::Aspects::MSOLE_ICON)
356  {
357  // Math objects change their object size during InsertObject.
358  // New size must be set in SdrObject, or a wrong scale will be set at
359  // ActivateObject.
360 
361  try
362  {
363  awt::Size aSz = xObj->getVisualAreaSize( nAspect );
364 
365  Size aNewSize( aSz.Width, aSz.Height );
366  aNewSize = OutputDevice::LogicToLogic(aNewSize, MapMode(aMapUnit), MapMode(MapUnit::Map100thMM));
367 
368  if ( aNewSize != aSize )
369  {
370  aRect.SetSize( aNewSize );
371  pObj->SetLogicRect( aRect );
372  }
373  }
374  catch( embed::NoVisualAreaSizeException& )
375  {}
376  }
377 
378  if ( !rReq.IsAPI() )
379  {
380  // XXX Activate from macro is deadly !!! ???
381  if (bIsFromFile)
382  {
383  // Object selected, activate Draw-Shell
384  rViewShell.SetDrawShell( true );
385  }
386  else if (bSuccess)
387  {
388  rViewShell.ActivateObject(pObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
389  }
390  }
391 
392  rReq.Done();
393  }
394  catch( uno::Exception& )
395  {
396  OSL_FAIL( "May need error handling here!" );
397  }
398  }
399  else
400  rReq.Ignore();
401 }
402 
405  : FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
406 {
407  const SfxItemSet* pReqArgs = rReq.GetArgs();
408 
409  if( ! rReq.IsAPI() )
410  rReq.Done();
411 
412  if (!SvtModuleOptions().IsChart())
413  return;
414 
415  // BM/IHA --
416 
417  // get range
418  OUString aRangeString;
419  bool bRangeIsPivotTable = false;
420  ScRange aPositionRange; // cell range for chart positioning
421  ScMarkData aMark = rViewSh.GetViewData().GetMarkData();
422  if( pReqArgs )
423  {
424  const SfxPoolItem* pItem;
425  if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
426  aRangeString = static_cast<const SfxStringItem*>(pItem)->GetValue();
427 
428  aPositionRange = rViewSh.GetViewData().GetCurPos();
429  }
430  else
431  {
432  ScDocument& rDocument = rViewSh.GetViewData().GetDocument();
433  ScDPObject* pObject = rDocument.GetDPAtCursor(rViewSh.GetViewData().GetCurX(),
434  rViewSh.GetViewData().GetCurY(),
435  rViewSh.GetViewData().GetTabNo());
436  if (pObject)
437  {
438  aRangeString = pObject->GetName();
439  bRangeIsPivotTable = true;
440  }
441  else
442  {
443  bool bAutomaticMark = false;
444  if ( !aMark.IsMarked() && !aMark.IsMultiMarked() )
445  {
446  rViewSh.GetViewData().GetView()->MarkDataArea();
447  bAutomaticMark = true;
448  }
449 
450  ScMarkData aMultiMark( aMark );
451  aMultiMark.MarkToMulti();
452 
453  ScRangeList aRanges;
454  aMultiMark.FillRangeListWithMarks( &aRanges, false );
455  OUString aStr;
456  aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, rDocument, rDocument.GetAddressConvention() );
457  aRangeString = aStr;
458 
459  // get "total" range for positioning
460  if ( !aRanges.empty() )
461  {
462  aPositionRange = aRanges[ 0 ];
463  for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i )
464  {
465  aPositionRange.ExtendTo( aRanges[ i ] );
466  }
467  }
468 
469  if(bAutomaticMark)
470  rViewSh.GetViewData().GetView()->Unmark();
471  }
472  }
473 
474  // adapted old code
475  pView->UnmarkAll();
476 
477  OUString aName;
478  const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
479 
480  uno::Reference < embed::XEmbeddedObject > xObj =
482 
483  uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
484  if( xObj.is())
485  xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
486 
487  uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
488  if (xChartDoc.is())
489  xChartDoc->createDefaultChart();
490 
491  // lock the model to suppress any internal updates
492  uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
493  if( xChartModel.is() )
494  xChartModel->lockControllers();
495 
496  // object size
497  awt::Size aSz = xObj->getVisualAreaSize( nAspect );
498  Size aSize( aSz.Width, aSz.Height );
499 
500  MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
501 
502  bool bSizeCh = false;
503  if (aSize.IsEmpty())
504  {
505  aSize.setWidth( 5000 );
506  aSize.setHeight( 5000 );
507  bSizeCh = true;
508  }
509  if (bSizeCh)
510  {
511  aSize = vcl::Window::LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( aMapUnit ) );
512  aSz.Width = aSize.Width();
513  aSz.Height = aSize.Height();
514  xObj->setVisualAreaSize( nAspect, aSz );
515  }
516 
517  ScViewData& rData = rViewSh.GetViewData();
518  ScDocShell* pScDocSh = rData.GetDocShell();
519  ScDocument& rScDoc = pScDocSh->GetDocument();
520  bool bUndo (rScDoc.IsUndoEnabled());
521 
522  if( pReqArgs )
523  {
524  const SfxPoolItem* pItem;
525  sal_uInt16 nToTable = 0;
526 
527  if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
528  {
529  if ( auto pUInt16Item = dynamic_cast<const SfxUInt16Item*>( pItem) )
530  nToTable = pUInt16Item->GetValue();
531  else if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
532  {
533  // In IDL for Basic FN_PARAM_4 means SfxBoolItem
534  // -> if set new table, else current table
535 
536  if ( pBoolItem->GetValue() )
537  nToTable = static_cast<sal_uInt16>(rScDoc.GetTableCount());
538  else
539  nToTable = static_cast<sal_uInt16>(rData.GetTabNo());
540  }
541  }
542  else
543  {
544  rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
545  }
546 
547  // Output on new table?
548  if ( nToTable == rScDoc.GetTableCount() )
549  {
550  // Let's go...
551  OUString aTabName;
552  SCTAB nNewTab = rScDoc.GetTableCount();
553 
554  rScDoc.CreateValidTabName( aTabName );
555 
556  if ( rScDoc.InsertTab( nNewTab, aTabName ) )
557  {
558  if (bUndo)
559  {
560  pScDocSh->GetUndoManager()->AddUndoAction(
561  std::make_unique<ScUndoInsertTab>( pScDocSh, nNewTab,
562  true/*bAppend*/, aTabName ) );
563  }
564 
565  pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
566  rViewSh.SetTabNo( nNewTab, true );
567  pScDocSh->PostPaintExtras();
568  }
569  else
570  {
571  OSL_FAIL( "Could not create new table :-/" );
572  }
573  }
574  else if ( nToTable != rData.GetTabNo() )
575  {
576  rViewSh.SetTabNo( nToTable, true );
577  }
578  }
579 
580  lcl_ChartInit(xObj, &rData, aRangeString, bRangeIsPivotTable); // set source range, auto-detect column/row headers
581 
582  // object position
583 
584  // get chart position (from window size and data range)
585  Point aStart = rViewSh.GetChartInsertPos( aSize, aPositionRange );
586 
587  tools::Rectangle aRect (aStart, aSize);
588  SdrOle2Obj* pObj = new SdrOle2Obj(
589  *pDoc, // TTTT should be reference
590  svt::EmbeddedObjectRef(xObj, nAspect),
591  aName,
592  aRect);
593  SdrPageView* pPV = pView->GetSdrPageView();
594 
595  // #i121334# This call will change the chart's default background fill from white to transparent.
596  // Add here again if this is wanted (see task description for details)
597  // ChartHelper::AdaptDefaultsForChart( xObj );
598 
599 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immediate redraw and asks the chart for a visual representation
600 
601  // use the page instead of the view to insert, so no undo action is created yet
602  SdrPage* pPage = pPV->GetPage();
603  pPage->InsertObject( pObj );
604  pView->UnmarkAllObj();
605  pView->MarkObj( pObj, pPV );
606 
607  if (rReq.IsAPI())
608  {
609  if( xChartModel.is() )
610  xChartModel->unlockControllers();
611  }
612  else if (!rViewSh.isLOKMobilePhone())
613  {
614  //the controller will be unlocked by the dialog when the dialog is told to do so
615 
616  // only activate object if not called via API (e.g. macro)
618  rViewShell.ActivateObject(pObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
619 
620  //open wizard
621  //@todo get context from calc if that has one
622  uno::Reference< uno::XComponentContext > xContext(
624  if(xContext.is())
625  {
626  uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
627  if(xMCF.is())
628  {
629  css::uno::Reference<css::ui::dialogs::XAsynchronousExecutableDialog> xDialog(
630  xMCF->createInstanceWithContext(
631  "com.sun.star.comp.chart2.WizardDialog"
632  , xContext), uno::UNO_QUERY);
633  uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
634  if( xChartModel.is() && xInit.is() )
635  {
636  uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
637  {
638  {"ParentWindow", uno::Any(uno::Reference< awt::XWindow >())},
639  {"ChartModel", uno::Any(xChartModel)}
640  }));
641  xInit->initialize( aSeq );
642 
643  // try to set the dialog's position so it doesn't hide the chart
644  uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
645  if ( xDialogProps.is() )
646  {
647  try
648  {
649  //get dialog size:
650  awt::Size aDialogAWTSize;
651  if( xDialogProps->getPropertyValue("Size")
652  >>= aDialogAWTSize )
653  {
654  Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
655  if ( !aDialogSize.IsEmpty() )
656  {
657  //calculate and set new position
658  Point aDialogPos = rViewShell.GetChartDialogPos( aDialogSize, aRect );
659  xDialogProps->setPropertyValue("Position",
660  uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
661  }
662  }
663  //tell the dialog to unlock controller
664  xDialogProps->setPropertyValue("UnlockControllersOnExecute",
665  uno::makeAny( true ) );
666 
667  }
668  catch( uno::Exception& )
669  {
670  OSL_FAIL( "Chart wizard couldn't be positioned automatically" );
671  }
672  }
673 
674  pView->AddUndo(std::make_unique<SdrUndoNewObj>(*pObj));
675  ::svt::DialogClosedListener* pListener = new ::svt::DialogClosedListener();
676  pListener->SetDialogClosedLink( rLink );
677  css::uno::Reference<css::ui::dialogs::XDialogClosedListener> xListener( pListener );
678 
679  xDialog->startExecuteModal( xListener );
680  }
681  else
682  {
683  uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
684  if( xComponent.is())
685  xComponent->dispose();
686  }
687  }
688  }
689  }
690 }
691 
692 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
SfxViewFrame * GetViewFrame() const
#define SO3_SM_CLASSID_60
void UnmarkAllObj(SdrPageView const *pPV=nullptr)
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:372
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
void MarkDataArea(bool bIncludeCursor=true)
Definition: tabview3.cxx:1651
virtual css::uno::Reference< css::io::XInputStream > GetIconIfIconified(OUString *pGraphicMediaType)=0
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void ActivateObject(SdrOle2Obj *pObj, tools::Long nVerb)
Definition: tabvwshb.cxx:144
bool isLOKMobilePhone() const
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:1002
void setWidth(tools::Long nWidth)
void MarkToMulti()
Definition: markdata.cxx:224
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void LimitChartIfAll(ScRangeListRef &rRangeList)
Definition: document.cxx:1123
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
Definition: rangelst.cxx:146
void Remove(const SvGlobalName &)
static SvxAbstractDialogFactory * Create()
Point GetChartInsertPos(const Size &rSize, const ScRange &rCellRange)
Definition: tabview.cxx:1680
SCROW GetCurY() const
Definition: viewdata.hxx:402
SC_DLLPUBLIC void ExtendTo(const ScRange &rRange)
Definition: address.cxx:1595
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
css::uno::Sequence< sal_Int8 > GetByteSequence() const
const ContentProperties & rData
void PostPaintExtras()
Definition: docsh3.cxx:196
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void Unmark()
Definition: tabview3.cxx:1718
void Done(bool bRemove=false)
const SvGlobalName & GetValue() const
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
css::uno::Reference< css::frame::XModel > GetModel() const
#define SC_TAB_INSERTED
Definition: uiitems.hxx:76
const SfxItemSet * GetArgs() const
virtual SfxObjectShell * GetObjectShell() override
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
EmbeddedObjectRef * pObject
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:489
static sal_uInt16 IsChart(const SvGlobalName &rName)
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2805
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:45
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
bool IsMultiMarked() const
Definition: markdata.hxx:83
int nCount
ScTabViewShell & rViewShell
Definition: fupoor.hxx:44
void UnmarkAll()
#define SO3_SCH_CLASSID_60
FuInsertOLE(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq)
Definition: fuins2.cxx:217
ScViewData & GetViewData()
Definition: tabview.hxx:332
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:954
bool empty() const
Definition: rangelst.hxx:89
bool IsMath() const
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
FuInsertChart(ScTabViewShell &pViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq, const Link< css::ui::dialogs::DialogClosedEvent *, void > &rLink)
Definition: fuins2.cxx:403
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define TOOLS_WARN_EXCEPTION(area, stream)
bool IsEmpty() const
bool IsMarked() const
Definition: markdata.hxx:82
int i
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
sal_Int16 SCCOL
Definition: types.hxx:22
#define SC_MOD()
Definition: scmod.hxx:253
void LimitChartArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow)
Definition: document.cxx:1115
void SetSize(const Size &rSize)
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1793
const OUString & GetName() const
Definition: dpobject.hxx:167
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:392
const T * GetArg(sal_uInt16 nSlotId) const
tools::Long Width() const
void SetDrawShell(bool bActive)
Definition: tabvwsh4.cxx:596
size_t size() const
Definition: rangelst.hxx:90
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1170
void SetGraphicStream(const css::uno::Reference< css::io::XInputStream > &xInGrStream, const OUString &rMediaType)
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
Definition: document.cxx:504
SCROW GetRowCount() const
Definition: chartpos.hxx:57
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
virtual void SetLogicRect(const tools::Rectangle &rRect)
Base class for all functions.
Definition: fupoor.hxx:40
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
ScAddress GetCurPos() const
Definition: viewdata.cxx:4007
virtual css::uno::Reference< css::embed::XEmbeddedObject > GetObject()=0
sal_Int32 SCROW
Definition: types.hxx:18
sal_uInt16 GetSlot() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
weld::Window * GetFrameWeld() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
SdrPage * GetPage() const
OUString aName
ScDrawView * pView
Definition: fupoor.hxx:43
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
tools::Long Height() const
Size GetSize(MapMode const *pTargetMapMode) const
Sequence< sal_Int8 > aSeq
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
SdrPageView * GetSdrPageView() const
virtual bool IsCreateNew()=0
void setHeight(tools::Long nHeight)
virtual SfxObjectShell * GetObjectShell() override
MapUnit
void AppendItem(const SfxPoolItem &)
Point GetInsertPos() const
Definition: tabview.cxx:1663
bool IsUndoEnabled() const
Definition: document.hxx:1531
void SetDialogClosedLink(const Link< css::ui::dialogs::DialogClosedEvent *, void > &rLink)
Point GetChartDialogPos(const Size &rDialogSize, const tools::Rectangle &rLogicChart)
Definition: tabview.cxx:1798
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
bool IsAPI() const
void Ignore()
aStr
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401