29#include <osl/diagnose.h>
31#include <drawview.hxx>
35#include <document.hxx>
46#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
47#include <com/sun/star/embed/Aspects.hpp>
48#include <com/sun/star/embed/XEmbeddedObject.hpp>
49#include <com/sun/star/chart2/XChartTypeContainer.hpp>
50#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
51#include <com/sun/star/chart2/XDataSeriesContainer.hpp>
52#include <com/sun/star/chart2/XChartDocument.hpp>
70 bool bAnyOle, bOneOle;
72 CheckOle( rMarkList, bAnyOle, bOneOle );
78 aDragShellRef->DoInitNew();
98 pTransferObj->SetDrawPersist( aDragShellRef.
get() );
99 pTransferObj->SetDragSource(
this );
101 SC_MOD()->SetDragObject(
nullptr, pTransferObj.get() );
107void getRangeFromDataSource( uno::Reference< chart2::data::XDataSource >
const & xDataSource, std::vector<OUString>& rRangeRep)
109 const uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence> > xSeqs = xDataSource->getDataSequences();
110 for (
const uno::Reference<chart2::data::XLabeledDataSequence>& xLS : xSeqs)
112 uno::Reference<chart2::data::XDataSequence> xSeq = xLS->getValues();
115 OUString aRep = xSeq->getSourceRangeRepresentation();
116 rRangeRep.push_back(aRep);
118 xSeq = xLS->getLabel();
121 OUString aRep = xSeq->getSourceRangeRepresentation();
122 rRangeRep.push_back(aRep);
127void getRangeFromErrorBar(
const uno::Reference< chart2::XChartDocument >& rChartDoc, std::vector<OUString>& rRangeRep)
129 uno::Reference <chart2::XDiagram > xDiagram = rChartDoc->getFirstDiagram();
133 uno::Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY);
134 if(!xCooSysContainer.is())
137 const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems());
138 for(
const auto& rCooSys : xCooSysSequence)
140 uno::Reference< chart2::XChartTypeContainer > xChartTypeContainer( rCooSys, uno::UNO_QUERY);
141 if(!xChartTypeContainer.is())
144 const uno::Sequence< uno::Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() );
145 for(
const auto& rChartType : xChartTypeSequence)
147 uno::Reference< chart2::XDataSeriesContainer > xDataSequenceContainer( rChartType, uno::UNO_QUERY);
148 if(!xDataSequenceContainer.is())
151 const uno::Sequence< uno::Reference< chart2::XDataSeries > > xSeriesSequence( xDataSequenceContainer->getDataSeries() );
152 for(
const uno::Reference<chart2::XDataSeries>& xSeries : xSeriesSequence)
154 uno::Reference< beans::XPropertySet > xPropSet( xSeries, uno::UNO_QUERY);
155 uno::Reference< chart2::data::XDataSource > xErrorBarY;
156 xPropSet->getPropertyValue(
"ErrorBarY") >>= xErrorBarY;
158 getRangeFromDataSource(xErrorBarY, rRangeRep);
159 uno::Reference< chart2::data::XDataSource > xErrorBarX;
160 xPropSet->getPropertyValue(
"ErrorBarX") >>= xErrorBarX;
162 getRangeFromDataSource(xErrorBarX, rRangeRep);
168void getRangeFromOle2Object(
const SdrOle2Obj& rObj, std::vector<OUString>& rRangeRep)
174 const uno::Reference<embed::XEmbeddedObject>& xObj = rObj.
GetObjRef();
178 uno::Reference<chart2::XChartDocument> xChartDoc(xObj->getComponent(), uno::UNO_QUERY);
182 if(xChartDoc->hasInternalDataProvider())
185 getRangeFromErrorBar(xChartDoc, rRangeRep);
187 uno::Reference<chart2::data::XDataSource> xDataSource(xChartDoc, uno::UNO_QUERY);
188 if (!xDataSource.is())
192 getRangeFromDataSource(xDataSource, rRangeRep);
198void getOleSourceRanges(
const SdrMarkList& rMarkList,
bool& rAnyOle,
bool& rOneOle, std::vector<ScRange>* pRanges =
nullptr,
const ScDocument* pDoc =
nullptr )
200 bool bCalcSourceRanges = pRanges && pDoc;
201 std::vector<OUString> aRangeReps;
202 rAnyOle = rOneOle =
false;
215 if (nSdrObjKind == SdrObjKind::OLE2)
219 if ( bCalcSourceRanges )
220 getRangeFromOle2Object(
static_cast<const SdrOle2Obj&
>( *pObj ), aRangeReps );
224 else if (
dynamic_cast<const SdrObjGroup*
>( pObj) !=
nullptr )
234 if ( !bCalcSourceRanges )
237 getRangeFromOle2Object(
static_cast<const SdrOle2Obj&
>( *pSubObj ), aRangeReps );
239 pSubObj = aIter.Next();
244 if (!bCalcSourceRanges)
248 for (
const auto& rRangeRep : aRangeReps)
254 pRanges->insert(pRanges->end(), aRange.
begin(), aRange.
end());
257 pRanges->push_back(aAddr);
265 std::vector<SCTAB>& mrTabs;
267 explicit InsertTabIndex(std::vector<SCTAB>& rTabs) : mrTabs(rTabs) {}
268 void operator() (
const ScRange& rRange)
281 void operator() (
const ScRange& rRange)
287 if (!mrDest.
GetTable(aTabName, nTab))
295void copyChartRefDataToClipDoc(
ScDocument& rSrcDoc,
ScDocument& rClipDoc,
const std::vector<ScRange>& rRanges)
298 std::vector<SCTAB> aTabs;
299 std::for_each(rRanges.begin(), rRanges.end(), InsertTabIndex(aTabs));
300 std::sort(aTabs.begin(), aTabs.end());
301 aTabs.erase(std::unique(aTabs.begin(), aTabs.end()), aTabs.end());
309 std::vector<SCTAB>::const_iterator it = aTabs.begin(), itEnd = aTabs.end();
310 if (!rSrcDoc.
GetName(*it, aName))
315 for (++it; it != itEnd; ++it)
317 if (!rSrcDoc.
GetName(*it, aName))
323 std::for_each(rRanges.begin(), rRanges.end(), CopyRangeData(rSrcDoc, rClipDoc));
330 getOleSourceRanges( rMarkList, rAnyOle, rOneOle );
336 std::vector<ScRange> aRanges;
337 bool bAnyOle =
false, bOneOle =
false;
338 getOleSourceRanges( rMarkList, bAnyOle, bOneOle, &aRanges, &
rDoc );
348 copyChartRefDataToClipDoc(
rDoc, rClipDoc, aRanges);
377 bool bAnyOle, bOneOle;
379 CheckOle( rMarkList, bAnyOle, bOneOle );
445 if (nIdent == SdrObjKind::OLE2)
448 uno::Reference < embed::XEmbeddedObject > xObj =
static_cast<SdrOle2Obj*
>(pObj)->GetObjRef();
451 sal_Int64 nAspect =
static_cast<SdrOle2Obj*
>(pObj)->GetAspect();
453 if ( nAspect == embed::Aspects::MSOLE_ICON )
455 MapMode aMapMode( MapUnit::Map100thMM );
456 aOriginalSize =
static_cast<SdrOle2Obj*
>(pObj)->GetOrigObjSize( &aMapMode );
464 awt::Size aSz = xObj->getVisualAreaSize(
static_cast<SdrOle2Obj*
>(pObj)->GetAspect() );
466 Size( aSz.Width, aSz.Height ),
470 }
catch( embed::NoVisualAreaSizeException& )
477 else if (nIdent == SdrObjKind::Graphic)
482 MapMode aDestMap( MapUnit::Map100thMM );
483 if (aSourceMap.
GetMapUnit() == MapUnit::MapPixel)
499 pUndoGroup->AddAction( std::make_unique<SdrUndoGeoObj>( *pObj ) );
508 pUndoGroup->SetComment(
ScResId( STR_UNDO_ORIGINALSIZE ));
521 SAL_WARN(
"sc.ui",
"Fit to cell only works with one graphic!");
530 SAL_WARN(
"sc.ui",
"Fit to cell only works with cell anchored graphics!");
537 SAL_WARN(
"sc.ui",
"Missing ScDrawObjData!");
549 assert(nWidth &&
"div-by-zero");
550 double fScaleX =
static_cast<double>(aCellRect.
GetWidth()) /
static_cast<double>(nWidth);
552 assert(nHeight &&
"div-by-zero");
553 double fScaleY =
static_cast<double>(aCellRect.
GetHeight()) /
static_cast<double>(nHeight);
554 double fScaleMin = std::min(fScaleX, fScaleY);
556 aCellRect.
setWidth(
static_cast<double>(aGraphicRect.
GetWidth()) * fScaleMin);
560 pUndoGroup->AddAction( std::make_unique<SdrUndoGeoObj>( *pObj ) );
566 pUndoGroup->SetComment(
ScResId( STR_UNDO_FITCELLSIZE ));
virtual std::unique_ptr< SdrModel > CreateMarkedObjModel() const override
MapMode GetPrefMapMode() const
OUString GetURLNoPass(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void SetScaleY(const Fraction &rScaleY)
MapUnit GetMapUnit() const
void SetScaleX(const Fraction &rScaleX)
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
void SetDrawModified()
SetDrawModified - without Formula update.
double GetOutputFactor() const
virtual SfxUndoManager * GetUndoManager() override
SC_DLLPUBLIC bool GetTable(const OUString &rName, SCTAB &rTab) const
void AppendTabOnLoad(const OUString &rName)
SC_DLLPUBLIC void CopyStaticToDocument(const ScRange &rSrcRange, SCTAB nDestTab, ScDocument &rDestDoc)
Copy only raw cell values to another document.
void SetTabNameOnLoad(SCTAB nTab, const OUString &rName)
SC_DLLPUBLIC bool GetTableArea(SCTAB nTab, SCCOL &rEndCol, SCROW &rEndRow, bool bCalcHiddens=false) const
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
static tools::Rectangle GetCellRect(const ScDocument &rDoc, const ScAddress &rPos, bool bMergedCell)
Returns the rectangle for the passed cell address in 1/100 mm.
static ScDrawObjData * GetObjData(SdrObject *pObj, bool bCreate=false)
static ScAnchorType GetAnchorType(const SdrObject &)
static void SetGlobalDrawPersist(SfxObjectShell *pPersist)
static void CalcScale(const ScDocument &rDoc, SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, const OutputDevice *pDev, const Fraction &rZoomX, const Fraction &rZoomY, double nPPTX, double nPPTY, Fraction &rScaleX, Fraction &rScaleY)
void CalcNormScale(Fraction &rFractX, Fraction &rFractY) const
void BeginDrag(vcl::Window *pWindow, const Point &rStartPos)
css::uno::Reference< css::datatransfer::XTransferable > CopyToTransferable()
static void CheckOle(const SdrMarkList &rMarkList, bool &rAnyOle, bool &rOneOle)
ScDocument & rDoc
needed ?
VclPtr< OutputDevice > pDev
void SetMarkedOriginalSize()
static SC_DLLPUBLIC double nScreenPPTX
Horizontal pixel per twips factor.
static SC_DLLPUBLIC double nScreenPPTY
Vertical pixel per twips factor.
static tools::SvRef< ScDocShell > xDrawClipDocShellRef
::std::vector< ScRange >::const_iterator begin() const
::std::vector< ScRange >::const_iterator end() const
ScRefFlags Parse(std::u16string_view, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, SCTAB nDefaultTab=0, sal_Unicode cDelimiter=0)
static SfxObjectShell * SetDrawClipDoc(bool bAnyOle, const std::shared_ptr< ScDocument > &={})
ScDocShell * GetDocShell() const
ScGridWindow * GetActiveWin()
virtual void BrkAction() override
const Graphic & GetGraphic() const
Size getOriginalSize() const
size_t GetMarkCount() const
SdrMark * GetMark(size_t nNum) const
const SdrMarkList & GetMarkedObjectList() const
bool AreObjectsMarked() const
const tools::Rectangle & GetAllMarkedRect() const
SdrObject * GetMarkedSdrObj() const
virtual const tools::Rectangle & GetSnapRect() const
virtual void AdjustToMaxRect(const tools::Rectangle &rMaxRect, bool bShrinkOnly=false)
virtual SdrObjKind GetObjIdentifier() const
virtual void SetSnapRect(const tools::Rectangle &rRect)
virtual bool shouldKeepAspectRatio() const
virtual const tools::Rectangle & GetLogicRect() const
virtual void Resize(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bUnsetRelative=true)
sal_Int64 GetAspect() const
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
SdrModel & GetModel() const
const INetURLObject & GetURLObject() const
void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc) const
SfxMedium * GetMedium() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
OUString ScResId(TranslateId aId)
#define DND_ACTION_COPYMOVE