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( 4 );
184  aArgs[0] = beans::PropertyValue(
185  "CellRangeRepresentation", -1,
186  uno::makeAny( aRangeString ), beans::PropertyState_DIRECT_VALUE );
187  aArgs[1] = beans::PropertyValue(
188  "HasCategories", -1,
189  uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE );
190  aArgs[2] = beans::PropertyValue(
191  "FirstCellAsLabel", -1,
192  uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE );
193  aArgs[3] = beans::PropertyValue(
194  "DataRowSource", -1,
195  uno::makeAny( eDataRowSource ), beans::PropertyState_DIRECT_VALUE );
196 
197  try
198  {
199  xReceiver->setArguments( aArgs );
200  }
201  catch (const lang::IllegalArgumentException&)
202  {
203  // Can happen for invalid aRangeString, in which case a Chart
204  // will be created nevertheless and the range string can be
205  // edited.
206  TOOLS_WARN_EXCEPTION("sc.ui",
207  "lcl_ChartInit - caught IllegalArgumentException might be due to aRangeString: " << aRangeString);
208  }
209 
210  // don't create chart listener here (range may be modified in chart dialog)
211 }
212 
213 }
214 
216  SdrModel* pDoc, SfxRequest& rReq)
217  : FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
218 {
219  if( ! rReq.IsAPI() )
220  rReq.Done();
221 
223 
224  uno::Reference < embed::XEmbeddedObject > xObj;
225  uno::Reference < embed::XStorage > xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
226  bool bIsFromFile = false;
227  OUString aName;
228 
229  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
230  OUString aIconMediaType;
231  uno::Reference< io::XInputStream > xIconMetaFile;
232 
233  const sal_uInt16 nSlot = rReq.GetSlot();
234  const SfxGlobalNameItem* pNameItem = rReq.GetArg<SfxGlobalNameItem>(SID_INSERT_OBJECT);
235  if ( nSlot == SID_INSERT_OBJECT && pNameItem )
236  {
237  const SvGlobalName& aClassName = pNameItem->GetValue();
239  }
240  else if ( nSlot == SID_INSERT_SMATH )
241  {
242  if ( SvtModuleOptions().IsMath() )
243  {
245  rReq.AppendItem( SfxGlobalNameItem( SID_INSERT_OBJECT, SvGlobalName( SO3_SM_CLASSID_60 ) ) );
246  }
247  }
248  else
249  {
250  SvObjectServerList aServerLst;
251  switch ( nSlot )
252  {
253  case SID_INSERT_OBJECT :
254  aServerLst.FillInsertObjects();
255  aServerLst.Remove( ScDocShell::Factory().GetClassId() ); // Do not show Starcalc
256  //TODO/LATER: currently no inserting of ClassId into SfxRequest!
257  [[fallthrough]]; //TODO ???
258  case SID_INSERT_FLOATINGFRAME :
259  {
262  pFact->CreateInsertObjectDialog( rViewShell.GetFrameWeld(), SC_MOD()->GetSlotPool()->GetSlot(nSlot)->GetCommandString(),
263  xStorage, &aServerLst ));
264  if ( pDlg )
265  {
266  pDlg->Execute();
267  xObj = pDlg->GetObject();
268 
269  xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
270  if ( xIconMetaFile.is() )
271  nAspect = embed::Aspects::MSOLE_ICON;
272 
273  if ( xObj.is() )
275  // to activate DrawShell (no need to activate Object)
276  bIsFromFile = !pDlg->IsCreateNew();
277  }
278 
279  break;
280  }
281  }
282  }
283 
284  // SvInsertObjectDialog (everything in one Dialog) are not used anymore
285  if (xObj.is())
286  {
287  pView->UnmarkAll();
288 
289  try
290  {
291  ::svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
292  Size aSize;
293  MapMode aMap100( MapUnit::Map100thMM );
294  MapUnit aMapUnit = MapUnit::Map100thMM;
295 
296  if ( nAspect == embed::Aspects::MSOLE_ICON )
297  {
298  aObjRef.SetGraphicStream( xIconMetaFile, aIconMediaType );
299  aSize = aObjRef.GetSize( &aMap100 );
300  }
301  else
302  {
303  awt::Size aSz;
304  try
305  {
306  aSz = xObj->getVisualAreaSize( nAspect );
307  }
308  catch( embed::NoVisualAreaSizeException& )
309  {
310  // the default size will be set later
311  }
312 
313  aSize = Size( aSz.Width, aSz.Height );
314 
315  aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
316  if (aSize.IsEmpty())
317  {
318  // rectangle with balanced edge ratio
319  aSize.setWidth( 5000 );
320  aSize.setHeight( 5000 );
321  Size aTmp = OutputDevice::LogicToLogic(aSize, MapMode(MapUnit::Map100thMM), MapMode(aMapUnit));
322  aSz.Width = aTmp.Width();
323  aSz.Height = aTmp.Height();
324  xObj->setVisualAreaSize( nAspect, aSz );
325 
326  // re-convert aSize to 1/100th mm to avoid rounding errors in comparison below
327  aSize = OutputDevice::LogicToLogic( aTmp,
328  MapMode( aMapUnit ), aMap100 );
329  }
330  else
331  aSize = OutputDevice::LogicToLogic( aSize,
332  MapMode( aMapUnit ), aMap100 );
333  }
334 
335  // initialize chart ?
336  if ( SvtModuleOptions().IsChart() && SotExchange::IsChart( SvGlobalName( xObj->getClassID() ) ) )
337  lcl_ChartInit(xObj, &rViewSh.GetViewData(), OUString(), false);
338 
339  ScViewData& rData = rViewSh.GetViewData();
340 
341  Point aPnt = rViewSh.GetInsertPos();
342  if ( rData.GetDocument().IsNegativePage( rData.GetTabNo() ) )
343  aPnt.AdjustX( -(aSize.Width()) ); // move position to left edge
344  tools::Rectangle aRect (aPnt, aSize);
345  SdrOle2Obj* pObj = new SdrOle2Obj(
346  *pDoc, // TTTT should be reference
347  aObjRef,
348  aName,
349  aRect);
350  SdrPageView* pPV = pView->GetSdrPageView();
351  bool bSuccess = pView->InsertObjectAtView(pObj, *pPV);
352 
353  if (bSuccess && nAspect != embed::Aspects::MSOLE_ICON)
354  {
355  // Math objects change their object size during InsertObject.
356  // New size must be set in SdrObject, or a wrong scale will be set at
357  // ActivateObject.
358 
359  try
360  {
361  awt::Size aSz = xObj->getVisualAreaSize( nAspect );
362 
363  Size aNewSize( aSz.Width, aSz.Height );
364  aNewSize = OutputDevice::LogicToLogic(aNewSize, MapMode(aMapUnit), MapMode(MapUnit::Map100thMM));
365 
366  if ( aNewSize != aSize )
367  {
368  aRect.SetSize( aNewSize );
369  pObj->SetLogicRect( aRect );
370  }
371  }
372  catch( embed::NoVisualAreaSizeException& )
373  {}
374  }
375 
376  if ( !rReq.IsAPI() )
377  {
378  // XXX Activate from macro is deadly !!! ???
379  if (bIsFromFile)
380  {
381  // Object selected, activate Draw-Shell
382  rViewShell.SetDrawShell( true );
383  }
384  else if (bSuccess)
385  {
386  rViewShell.ActivateObject(pObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
387  }
388  }
389 
390  rReq.Done();
391  }
392  catch( uno::Exception& )
393  {
394  OSL_FAIL( "May need error handling here!" );
395  }
396  }
397  else
398  rReq.Ignore();
399 }
400 
403  : FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
404 {
405  const SfxItemSet* pReqArgs = rReq.GetArgs();
406 
407  if( ! rReq.IsAPI() )
408  rReq.Done();
409 
410  if (!SvtModuleOptions().IsChart())
411  return;
412 
413  // BM/IHA --
414 
415  // get range
416  OUString aRangeString;
417  bool bRangeIsPivotTable = false;
418  ScRange aPositionRange; // cell range for chart positioning
419  ScMarkData aMark = rViewSh.GetViewData().GetMarkData();
420  if( pReqArgs )
421  {
422  const SfxPoolItem* pItem;
423  if( pReqArgs->HasItem( FN_PARAM_5, &pItem ) )
424  aRangeString = static_cast<const SfxStringItem*>(pItem)->GetValue();
425 
426  aPositionRange = rViewSh.GetViewData().GetCurPos();
427  }
428  else
429  {
430  ScDocument& rDocument = rViewSh.GetViewData().GetDocument();
431  ScDPObject* pObject = rDocument.GetDPAtCursor(rViewSh.GetViewData().GetCurX(),
432  rViewSh.GetViewData().GetCurY(),
433  rViewSh.GetViewData().GetTabNo());
434  if (pObject)
435  {
436  aRangeString = pObject->GetName();
437  bRangeIsPivotTable = true;
438  }
439  else
440  {
441  bool bAutomaticMark = false;
442  if ( !aMark.IsMarked() && !aMark.IsMultiMarked() )
443  {
444  rViewSh.GetViewData().GetView()->MarkDataArea();
445  bAutomaticMark = true;
446  }
447 
448  ScMarkData aMultiMark( aMark );
449  aMultiMark.MarkToMulti();
450 
451  ScRangeList aRanges;
452  aMultiMark.FillRangeListWithMarks( &aRanges, false );
453  OUString aStr;
454  aRanges.Format( aStr, ScRefFlags::RANGE_ABS_3D, rDocument, rDocument.GetAddressConvention() );
455  aRangeString = aStr;
456 
457  // get "total" range for positioning
458  if ( !aRanges.empty() )
459  {
460  aPositionRange = aRanges[ 0 ];
461  for ( size_t i = 1, nCount = aRanges.size(); i < nCount; ++i )
462  {
463  aPositionRange.ExtendTo( aRanges[ i ] );
464  }
465  }
466 
467  if(bAutomaticMark)
468  rViewSh.GetViewData().GetView()->Unmark();
469  }
470  }
471 
472  // adapted old code
473  pView->UnmarkAll();
474 
475  OUString aName;
476  const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
477 
478  uno::Reference < embed::XEmbeddedObject > xObj =
480 
481  uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
482  if( xObj.is())
483  xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
484 
485  uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
486  if (xChartDoc.is())
487  xChartDoc->createDefaultChart();
488 
489  // lock the model to suppress any internal updates
490  uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
491  if( xChartModel.is() )
492  xChartModel->lockControllers();
493 
494  // object size
495  awt::Size aSz = xObj->getVisualAreaSize( nAspect );
496  Size aSize( aSz.Width, aSz.Height );
497 
498  MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
499 
500  bool bSizeCh = false;
501  if (aSize.IsEmpty())
502  {
503  aSize.setWidth( 5000 );
504  aSize.setHeight( 5000 );
505  bSizeCh = true;
506  }
507  if (bSizeCh)
508  {
509  aSize = OutputDevice::LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( aMapUnit ) );
510  aSz.Width = aSize.Width();
511  aSz.Height = aSize.Height();
512  xObj->setVisualAreaSize( nAspect, aSz );
513  }
514 
515  ScViewData& rData = rViewSh.GetViewData();
516  ScDocShell* pScDocSh = rData.GetDocShell();
517  ScDocument& rScDoc = pScDocSh->GetDocument();
518  bool bUndo (rScDoc.IsUndoEnabled());
519 
520  if( pReqArgs )
521  {
522  const SfxPoolItem* pItem;
523  sal_uInt16 nToTable = 0;
524 
525  if( pReqArgs->HasItem( FN_PARAM_4, &pItem ) )
526  {
527  if ( auto pUInt16Item = dynamic_cast<const SfxUInt16Item*>( pItem) )
528  nToTable = pUInt16Item->GetValue();
529  else if ( auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
530  {
531  // In IDL for Basic FN_PARAM_4 means SfxBoolItem
532  // -> if set new table, else current table
533 
534  if ( pBoolItem->GetValue() )
535  nToTable = static_cast<sal_uInt16>(rScDoc.GetTableCount());
536  else
537  nToTable = static_cast<sal_uInt16>(rData.GetTabNo());
538  }
539  }
540  else
541  {
542  rReq.AppendItem( SfxUInt16Item( FN_PARAM_4, nToTable ) );
543  }
544 
545  // Output on new table?
546  if ( nToTable == rScDoc.GetTableCount() )
547  {
548  // Let's go...
549  OUString aTabName;
550  SCTAB nNewTab = rScDoc.GetTableCount();
551 
552  rScDoc.CreateValidTabName( aTabName );
553 
554  if ( rScDoc.InsertTab( nNewTab, aTabName ) )
555  {
556  if (bUndo)
557  {
558  pScDocSh->GetUndoManager()->AddUndoAction(
559  std::make_unique<ScUndoInsertTab>( pScDocSh, nNewTab,
560  true/*bAppend*/, aTabName ) );
561  }
562 
563  pScDocSh->Broadcast( ScTablesHint( SC_TAB_INSERTED, nNewTab ) );
564  rViewSh.SetTabNo( nNewTab, true );
565  pScDocSh->PostPaintExtras();
566  }
567  else
568  {
569  OSL_FAIL( "Could not create new table :-/" );
570  }
571  }
572  else if ( nToTable != rData.GetTabNo() )
573  {
574  rViewSh.SetTabNo( nToTable, true );
575  }
576  }
577 
578  lcl_ChartInit(xObj, &rData, aRangeString, bRangeIsPivotTable); // set source range, auto-detect column/row headers
579 
580  // object position
581 
582  // get chart position (from window size and data range)
583  Point aStart = rViewSh.GetChartInsertPos( aSize, aPositionRange );
584 
585  tools::Rectangle aRect (aStart, aSize);
586  SdrOle2Obj* pObj = new SdrOle2Obj(
587  *pDoc, // TTTT should be reference
588  svt::EmbeddedObjectRef(xObj, nAspect),
589  aName,
590  aRect);
591  SdrPageView* pPV = pView->GetSdrPageView();
592 
593  // #i121334# This call will change the chart's default background fill from white to transparent.
594  // Add here again if this is wanted (see task description for details)
595  // ChartHelper::AdaptDefaultsForChart( xObj );
596 
597 // pView->InsertObjectAtView(pObj, *pPV);//this call leads to an immediate redraw and asks the chart for a visual representation
598 
599  // use the page instead of the view to insert, so no undo action is created yet
600  SdrPage* pPage = pPV->GetPage();
601  pPage->InsertObject( pObj );
602  pView->UnmarkAllObj();
603  pView->MarkObj( pObj, pPV );
604 
605  if (rReq.IsAPI())
606  {
607  if( xChartModel.is() )
608  xChartModel->unlockControllers();
609  }
610  else if (!rViewSh.isLOKMobilePhone())
611  {
612  //the controller will be unlocked by the dialog when the dialog is told to do so
613 
614  // only activate object if not called via API (e.g. macro)
616  rViewShell.ActivateObject(pObj, embed::EmbedVerbs::MS_OLEVERB_SHOW);
617 
618  //open wizard
619  //@todo get context from calc if that has one
620  uno::Reference< uno::XComponentContext > xContext(
622  if(xContext.is())
623  {
624  uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
625  if(xMCF.is())
626  {
627  css::uno::Reference<css::ui::dialogs::XAsynchronousExecutableDialog> xDialog(
628  xMCF->createInstanceWithContext(
629  "com.sun.star.comp.chart2.WizardDialog"
630  , xContext), uno::UNO_QUERY);
631  uno::Reference< lang::XInitialization > xInit( xDialog, uno::UNO_QUERY );
632  if( xChartModel.is() && xInit.is() )
633  {
634  uno::Sequence<uno::Any> aSeq(comphelper::InitAnyPropertySequence(
635  {
636  {"ParentWindow", uno::Any(uno::Reference< awt::XWindow >())},
637  {"ChartModel", uno::Any(xChartModel)}
638  }));
639  xInit->initialize( aSeq );
640 
641  // try to set the dialog's position so it doesn't hide the chart
642  uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
643  if ( xDialogProps.is() )
644  {
645  try
646  {
647  //get dialog size:
648  awt::Size aDialogAWTSize;
649  if( xDialogProps->getPropertyValue("Size")
650  >>= aDialogAWTSize )
651  {
652  Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
653  if ( !aDialogSize.IsEmpty() )
654  {
655  //calculate and set new position
656  Point aDialogPos = rViewShell.GetChartDialogPos( aDialogSize, aRect );
657  xDialogProps->setPropertyValue("Position",
658  uno::makeAny( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
659  }
660  }
661  //tell the dialog to unlock controller
662  xDialogProps->setPropertyValue("UnlockControllersOnExecute",
663  uno::makeAny( true ) );
664 
665  }
666  catch( uno::Exception& )
667  {
668  OSL_FAIL( "Chart wizard couldn't be positioned automatically" );
669  }
670  }
671 
672  pView->AddUndo(std::make_unique<SdrUndoNewObj>(*pObj));
673  rtl::Reference<::svt::DialogClosedListener> pListener = new ::svt::DialogClosedListener();
674  pListener->SetDialogClosedLink( rLink );
675 
676  xDialog->startExecuteModal( pListener );
677  }
678  else
679  {
680  uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
681  if( xComponent.is())
682  xComponent->dispose();
683  }
684  }
685  }
686  }
687 }
688 
689 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3099
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:993
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: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
SC_DLLPUBLIC void ExtendTo(const ScRange &rRange)
Definition: address.cxx:1604
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:387
css::uno::Sequence< sal_Int8 > GetByteSequence() const
const ContentProperties & rData
void PostPaintExtras()
Definition: docsh3.cxx:197
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:2806
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:313
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:215
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:401
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:166
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:391
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:1173
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:503
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:855
ScAddress GetCurPos() const
Definition: viewdata.cxx:4067
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: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:1669
bool IsUndoEnabled() const
Definition: document.hxx:1534
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