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