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>
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/lang/XInitialization.hpp>
55 #include <com/sun/star/frame/XModel.hpp>
56 #include <com/sun/star/chart/ChartDataRowSource.hpp>
62 #include <fuinsert.hxx>
67 #include <document.hxx>
69 #include <uiitems.hxx>
70 #include <drawview.hxx>
80 void lcl_ChartInit(
const uno::Reference <embed::XEmbeddedObject>& xObj,
ScViewData* pViewData,
81 const OUString& rRangeParam,
bool bRangeIsPivotTable)
86 OUString aRangeString(rRangeParam);
88 if (aRangeString.isEmpty() && !bRangeIsPivotTable)
105 if (nCol2 >= nCol1 || nRow2 >= nRow1)
110 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
116 if (aRangeString.isEmpty())
121 uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
123 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
124 OSL_ASSERT( xReceiver.is());
125 if( !xReceiver.is() )
128 uno::Reference<chart2::data::XDataProvider> xDataProvider;
129 if (bRangeIsPivotTable)
132 pPivotTableDataProvider->setPivotTableName(aRangeString);
133 xDataProvider = pPivotTableDataProvider;
140 xReceiver->attachDataProvider(xDataProvider);
142 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->
GetModel(), uno::UNO_QUERY );
143 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
146 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
147 bool bHasCategories =
false;
148 bool bFirstCellAsLabel =
false;
153 if ( !aRangeListRef->empty() )
160 aRangeString = aTmpStr;
168 eDataRowSource = chart::ChartDataRowSource_ROWS;
170 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
172 bHasCategories = aChartPositioner.HasRowHeaders();
173 bFirstCellAsLabel = aChartPositioner.HasColHeaders();
177 bHasCategories = aChartPositioner.HasColHeaders();
178 bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
182 uno::Sequence< beans::PropertyValue > aArgs{
183 beans::PropertyValue(
184 "CellRangeRepresentation", -1,
185 uno::Any( aRangeString ), beans::PropertyState_DIRECT_VALUE ),
186 beans::PropertyValue(
188 uno::Any( bHasCategories ), beans::PropertyState_DIRECT_VALUE ),
189 beans::PropertyValue(
190 "FirstCellAsLabel", -1,
191 uno::Any( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE ),
192 beans::PropertyValue(
194 uno::Any( eDataRowSource ), beans::PropertyState_DIRECT_VALUE )
199 xReceiver->setArguments( aArgs );
201 catch (
const lang::IllegalArgumentException&)
207 "lcl_ChartInit - caught IllegalArgumentException might be due to aRangeString: " << aRangeString);
217 :
FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
224 uno::Reference < embed::XEmbeddedObject > xObj;
226 bool bIsFromFile =
false;
229 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
230 OUString aIconMediaType;
231 uno::Reference< io::XInputStream > xIconMetaFile;
233 const sal_uInt16 nSlot = rReq.
GetSlot();
235 if ( nSlot == SID_INSERT_OBJECT && pNameItem )
240 else if ( nSlot == SID_INSERT_SMATH )
253 case SID_INSERT_OBJECT :
255 aServerLst.
Remove( ScDocShell::Factory().GetClassId() );
258 case SID_INSERT_FLOATINGFRAME :
263 xStorage, &aServerLst ));
270 if ( xIconMetaFile.is() )
271 nAspect = embed::Aspects::MSOLE_ICON;
293 MapMode aMap100( MapUnit::Map100thMM );
294 MapUnit aMapUnit = MapUnit::Map100thMM;
296 if ( nAspect == embed::Aspects::MSOLE_ICON )
299 aSize = aObjRef.
GetSize( &aMap100 );
306 aSz = xObj->getVisualAreaSize( nAspect );
308 catch( embed::NoVisualAreaSizeException& )
313 aSize =
Size( aSz.Width, aSz.Height );
322 aSz.Width = aTmp.
Width();
323 aSz.Height = aTmp.
Height();
324 xObj->setVisualAreaSize( nAspect, aSz );
328 MapMode( aMapUnit ), aMap100 );
332 MapMode( aMapUnit ), aMap100 );
337 lcl_ChartInit(xObj, &rViewSh.
GetViewData(), OUString(),
false);
343 aPnt.AdjustX( -(aSize.
Width()) );
353 if (bSuccess && nAspect != embed::Aspects::MSOLE_ICON)
361 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
363 Size aNewSize( aSz.Width, aSz.Height );
366 if ( aNewSize != aSize )
372 catch( embed::NoVisualAreaSizeException& )
392 catch( uno::Exception& )
394 OSL_FAIL(
"May need error handling here!" );
403 :
FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
416 OUString aRangeString;
417 bool bRangeIsPivotTable =
false;
423 if( pReqArgs->
HasItem( FN_PARAM_5, &pItem ) )
424 aRangeString = static_cast<const SfxStringItem*>(pItem)->GetValue();
436 aRangeString = pObject->
GetName();
437 bRangeIsPivotTable =
true;
441 bool bAutomaticMark =
false;
445 bAutomaticMark =
true;
458 if ( !aRanges.
empty() )
460 aPositionRange = aRanges[ 0 ];
476 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
478 uno::Reference < embed::XEmbeddedObject > xObj =
481 uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
483 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
485 uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
487 xChartDoc->createDefaultChart();
490 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
491 if( xChartModel.is() )
492 xChartModel->lockControllers();
495 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
496 Size aSize( aSz.Width, aSz.Height );
500 bool bSizeCh =
false;
510 aSz.Width = aSize.
Width();
511 aSz.Height = aSize.
Height();
512 xObj->setVisualAreaSize( nAspect, aSz );
523 sal_uInt16 nToTable = 0;
525 if( pReqArgs->
HasItem( FN_PARAM_4, &pItem ) )
527 if (
auto pUInt16Item = dynamic_cast<const SfxUInt16Item*>( pItem) )
528 nToTable = pUInt16Item->GetValue();
529 else if (
auto pBoolItem = dynamic_cast<const SfxBoolItem*>( pItem) )
534 if ( pBoolItem->GetValue() )
537 nToTable =
static_cast<sal_uInt16
>(rData.
GetTabNo());
554 if ( rScDoc.
InsertTab( nNewTab, aTabName ) )
559 std::make_unique<ScUndoInsertTab>( pScDocSh, nNewTab,
569 OSL_FAIL(
"Could not create new table :-/" );
572 else if ( nToTable != rData.
GetTabNo() )
578 lcl_ChartInit(xObj, &rData, aRangeString, bRangeIsPivotTable);
607 if( xChartModel.is() )
608 xChartModel->unlockControllers();
620 uno::Reference< uno::XComponentContext > xContext(
624 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
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() )
636 {
"ParentWindow",
uno::Any(uno::Reference< awt::XWindow >())},
637 {
"ChartModel",
uno::Any(xChartModel)}
639 xInit->initialize( aSeq );
642 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
643 if ( xDialogProps.is() )
648 awt::Size aDialogAWTSize;
649 if( xDialogProps->getPropertyValue(
"Size")
652 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
657 xDialogProps->setPropertyValue(
"Position",
658 uno::Any( awt::Point(aDialogPos.getX(),aDialogPos.getY()) ) );
662 xDialogProps->setPropertyValue(
"UnlockControllersOnExecute",
666 catch( uno::Exception& )
668 OSL_FAIL(
"Chart wizard couldn't be positioned automatically" );
674 pListener->SetDialogClosedLink( rLink );
676 xDialog->startExecuteModal( pListener );
680 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
682 xComponent->dispose();
ScMarkData & GetMarkData()
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
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
void MarkDataArea(bool bIncludeCursor=true)
virtual css::uno::Reference< css::io::XInputStream > GetIconIfIconified(OUString *pGraphicMediaType)=0
ScDocShell * GetDocShell() const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
bool isLOKMobilePhone() const
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
void setWidth(tools::Long nWidth)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void LimitChartIfAll(ScRangeListRef &rRangeList)
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
void Remove(const SvGlobalName &)
static SvxAbstractDialogFactory * Create()
Point GetChartInsertPos(const Size &rSize, const ScRange &rCellRange)
void ExtendTo(const ScRange &rRange)
css::uno::Reference< css::frame::XModel3 > GetModel() const
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
css::uno::Sequence< sal_Int8 > GetByteSequence() const
const ContentProperties & rData
void Done(bool bRemove=false)
const SvGlobalName & GetValue() const
ScDocument & GetDocument() const
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
static sal_uInt16 IsChart(const SvGlobalName &rName)
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
virtual SfxUndoManager * GetUndoManager() override
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 ...
SC_DLLPUBLIC SCTAB GetTableCount() const
bool IsMultiMarked() const
ScTabViewShell & rViewShell
#define SO3_SCH_CLASSID_60
FuInsertOLE(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq)
ScViewData & GetViewData()
void PutInOrder(T &nStart, T &nEnd)
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)
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)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
void LimitChartArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow)
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
const OUString & GetName() const
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
const T * GetArg(sal_uInt16 nSlotId) const
void SetDrawShell(bool bActive)
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
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)
SCROW GetRowCount() const
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
virtual void SetLogicRect(const tools::Rectangle &rRect)
Base class for all functions.
ScDBFunc * GetView() const
ScAddress GetCurPos() const
void ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
virtual css::uno::Reference< css::embed::XEmbeddedObject > GetObject()=0
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
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
Size GetSize(MapMode const *pTargetMapMode) const
Sequence< sal_Int8 > aSeq
const ScDocument & GetDocument() const
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
void AppendItem(const SfxPoolItem &)
Point GetInsertPos() const
bool IsUndoEnabled() const
Point GetChartDialogPos(const Size &rDialogSize, const tools::Rectangle &rLogicChart)
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)