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>
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/XAsynchronousExecutableDialog.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>
63#include <fuinsert.hxx>
68#include <document.hxx>
71#include <drawview.hxx>
81void lcl_ChartInit(
const uno::Reference <embed::XEmbeddedObject>& xObj,
ScViewData* pViewData,
82 const OUString& rRangeParam,
bool bRangeIsPivotTable)
87 OUString aRangeString(rRangeParam);
89 if (aRangeString.isEmpty() && !bRangeIsPivotTable)
106 if (nCol2 >= nCol1 || nRow2 >= nRow1)
111 ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
117 if (aRangeString.isEmpty())
122 uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
124 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
125 OSL_ASSERT( xReceiver.is());
126 if( !xReceiver.is() )
129 uno::Reference<chart2::data::XDataProvider> xDataProvider;
130 if (bRangeIsPivotTable)
133 pPivotTableDataProvider->setPivotTableName(aRangeString);
134 xDataProvider = pPivotTableDataProvider;
141 xReceiver->attachDataProvider(xDataProvider);
143 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( getXWeak(pDocShell->
GetModel()), uno::UNO_QUERY );
144 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
147 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
148 bool bHasCategories =
false;
149 bool bFirstCellAsLabel =
false;
154 if ( !aRangeListRef->empty() )
161 aRangeString = aTmpStr;
167 SCSIZE nRowCount = pPositionMap->GetRowCount();
169 eDataRowSource = chart::ChartDataRowSource_ROWS;
171 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
173 bHasCategories = aChartPositioner.HasRowHeaders();
174 bFirstCellAsLabel = aChartPositioner.HasColHeaders();
178 bHasCategories = aChartPositioner.HasColHeaders();
179 bFirstCellAsLabel = aChartPositioner.HasRowHeaders();
183 uno::Sequence< beans::PropertyValue > aArgs{
184 beans::PropertyValue(
185 "CellRangeRepresentation", -1,
186 uno::Any( aRangeString ), beans::PropertyState_DIRECT_VALUE ),
187 beans::PropertyValue(
189 uno::Any( bHasCategories ), beans::PropertyState_DIRECT_VALUE ),
190 beans::PropertyValue(
191 "FirstCellAsLabel", -1,
192 uno::Any( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE ),
193 beans::PropertyValue(
195 uno::Any( eDataRowSource ), beans::PropertyState_DIRECT_VALUE )
200 xReceiver->setArguments( aArgs );
202 catch (
const lang::IllegalArgumentException&)
208 "lcl_ChartInit - caught IllegalArgumentException might be due to aRangeString: " << aRangeString);
218 :
FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
225 uno::Reference < embed::XEmbeddedObject > xObj;
227 bool bIsFromFile =
false;
230 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
231 OUString aIconMediaType;
232 uno::Reference< io::XInputStream > xIconMetaFile;
234 const sal_uInt16 nSlot = rReq.
GetSlot();
236 if ( nSlot == SID_INSERT_OBJECT && pNameItem )
241 else if ( nSlot == SID_INSERT_SMATH )
254 case SID_INSERT_OBJECT :
256 aServerLst.
Remove( ScDocShell::Factory().GetClassId() );
259 case SID_INSERT_FLOATINGFRAME :
264 xStorage, &aServerLst ));
268 xObj = pDlg->GetObject();
270 xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
271 if ( xIconMetaFile.is() )
272 nAspect = embed::Aspects::MSOLE_ICON;
277 bIsFromFile = !pDlg->IsCreateNew();
294 MapMode aMap100( MapUnit::Map100thMM );
295 MapUnit aMapUnit = MapUnit::Map100thMM;
297 if ( nAspect == embed::Aspects::MSOLE_ICON )
300 aSize = aObjRef.
GetSize( &aMap100 );
307 aSz = xObj->getVisualAreaSize( nAspect );
309 catch( embed::NoVisualAreaSizeException& )
314 aSize =
Size( aSz.Width, aSz.Height );
323 aSz.Width = aTmp.
Width();
324 aSz.Height = aTmp.
Height();
325 xObj->setVisualAreaSize( nAspect, aSz );
329 MapMode( aMapUnit ), aMap100 );
333 MapMode( aMapUnit ), aMap100 );
338 lcl_ChartInit(xObj, &rViewSh.
GetViewData(), OUString(),
false);
354 if (bSuccess && nAspect != embed::Aspects::MSOLE_ICON)
362 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
364 Size aNewSize( aSz.Width, aSz.Height );
367 if ( aNewSize != aSize )
370 pObj->SetLogicRect( aRect );
373 catch( embed::NoVisualAreaSizeException& )
393 catch( uno::Exception& )
395 OSL_FAIL(
"May need error handling here!" );
404 :
FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
417 OUString aRangeString;
418 bool bRangeIsPivotTable =
false;
424 if( pReqArgs->
HasItem( FN_PARAM_5, &pItem ) )
437 aRangeString =
pObject->GetName();
438 bRangeIsPivotTable =
true;
442 bool bAutomaticMark =
false;
446 bAutomaticMark =
true;
459 if ( !aRanges.
empty() )
461 aPositionRange = aRanges[ 0 ];
477 const sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
479 uno::Reference < embed::XEmbeddedObject > xObj =
482 uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
484 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
486 uno::Reference<chart2::XChartDocument> xChartDoc(xReceiver, uno::UNO_QUERY);
488 xChartDoc->createDefaultChart();
491 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
492 if( xChartModel.is() )
493 xChartModel->lockControllers();
496 awt::Size aSz = xObj->getVisualAreaSize( nAspect );
497 Size aSize( aSz.Width, aSz.Height );
501 bool bSizeCh =
false;
511 aSz.Width = aSize.
Width();
512 aSz.Height = aSize.
Height();
513 xObj->setVisualAreaSize( nAspect, aSz );
524 sal_uInt16 nToTable = 0;
526 if( pReqArgs->
HasItem( FN_PARAM_4, &pItem ) )
528 if (
auto pUInt16Item =
dynamic_cast<const SfxUInt16Item*
>( pItem) )
529 nToTable = pUInt16Item->GetValue();
530 else if (
auto pBoolItem =
dynamic_cast<const SfxBoolItem*
>( pItem) )
535 if ( pBoolItem->GetValue() )
538 nToTable =
static_cast<sal_uInt16
>(rData.
GetTabNo());
555 if ( rScDoc.
InsertTab( nNewTab, aTabName ) )
560 std::make_unique<ScUndoInsertTab>( pScDocSh, nNewTab,
570 OSL_FAIL(
"Could not create new table :-/" );
573 else if ( nToTable != rData.
GetTabNo() )
579 lcl_ChartInit(xObj, &rData, aRangeString, bRangeIsPivotTable);
608 if( xChartModel.is() )
609 xChartModel->unlockControllers();
621 uno::Reference< uno::XComponentContext > xContext(
622 ::cppu::defaultBootstrap_InitialComponentContext() );
625 uno::Reference< lang::XMultiComponentFactory > xMCF( xContext->getServiceManager() );
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() )
635 css::uno::Reference< css::awt::XWindow > xParent
639 {
"ParentWindow",
uno::Any(xParent)},
640 {
"ChartModel",
uno::Any(xChartModel)}
642 xInit->initialize(
aSeq );
645 uno::Reference < beans::XPropertySet > xDialogProps( xDialog, uno::UNO_QUERY );
646 if ( xDialogProps.is() )
651 awt::Size aDialogAWTSize;
652 if( xDialogProps->getPropertyValue(
"Size")
655 Size aDialogSize( aDialogAWTSize.Width, aDialogAWTSize.Height );
660 xDialogProps->setPropertyValue(
"Position",
665 xDialogProps->setPropertyValue(
"UnlockControllersOnExecute",
669 catch( uno::Exception& )
671 OSL_FAIL(
"Chart wizard couldn't be positioned automatically" );
677 pListener->SetDialogClosedLink( rLink );
679 xDialog->startExecuteModal( pListener );
683 uno::Reference< lang::XComponent > xComponent( xDialog, uno::UNO_QUERY );
685 xComponent->dispose();
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 ...
void PutInOrder(T &nStart, T &nEnd)
FuInsertChart(ScTabViewShell &pViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq, const Link< css::ui::dialogs::DialogClosedEvent *, void > &rLink)
FuInsertOLE(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq)
Base class for all functions.
ScTabViewShell & rViewShell
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long getX() const
constexpr tools::Long getY() const
const ScDocument & GetDocument() const
ScModelObj * GetModel() const
virtual SfxUndoManager * GetUndoManager() override
SC_DLLPUBLIC bool InsertTab(SCTAB nPos, const OUString &rName, bool bExternalDocument=false, bool bUndoDeleteTab=false)
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
void LimitChartArea(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow, SCCOL &rEndCol, SCROW &rEndRow)
void LimitChartIfAll(ScRangeListRef &rRangeList)
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
bool IsUndoEnabled() const
SC_DLLPUBLIC SCTAB GetTableCount() const
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
bool IsMultiMarked() const
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
void ExtendTo(const ScRange &rRange)
void ActivateObject(SdrOle2Obj *pObj, sal_Int32 nVerb)
void SetDrawShell(bool bActive)
void MarkDataArea(bool bIncludeCursor=true)
Point GetChartInsertPos(const Size &rSize, const ScRange &rCellRange)
Point GetChartDialogPos(const Size &rDialogSize, const tools::Rectangle &rLogicChart)
Point GetInsertPos() const
ScViewData & GetViewData()
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
ScMarkData & GetMarkData()
ScDocument & GetDocument() const
ScDocShell * GetDocShell() const
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
ScDBFunc * GetView() const
ScAddress GetCurPos() const
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
void UnmarkAllObj(SdrPageView const *pPV=nullptr)
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
SdrPage * GetPage() const
SdrPageView * GetSdrPageView() const
const SvGlobalName & GetValue() const
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
sal_uInt16 GetSlot() const
const SfxItemSet * GetArgs() const
const T * GetArg(sal_uInt16 nSlotId) const
void AppendItem(const SfxPoolItem &)
void Done(bool bRemove=false)
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
virtual SfxObjectShell * GetObjectShell() override
bool isLOKMobilePhone() const
weld::Window * GetFrameWeld() const
SfxViewFrame & GetViewFrame() const
virtual SfxObjectShell * GetObjectShell() override
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
static sal_uInt16 IsChart(const SvGlobalName &rName)
css::uno::Sequence< sal_Int8 > GetByteSequence() const
void Remove(const SvGlobalName &)
static SvxAbstractDialogFactory * Create()
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
static css::uno::Reference< css::embed::XStorage > GetTemporaryStorage(const css::uno::Reference< css::uno::XComponentContext > &rxContext=css::uno::Reference< css::uno::XComponentContext >())
#define SO3_SM_CLASSID_60
#define SO3_SCH_CLASSID_60
void SetGraphicStream(const css::uno::Reference< css::io::XInputStream > &xInGrStream, const OUString &rMediaType)
Size GetSize(MapMode const *pTargetMapMode) const
weld::Window * GetFrameWeld() const
#define TOOLS_WARN_EXCEPTION(area, stream)
EmbeddedObjectRef * pObject
Sequence< sal_Int8 > aSeq
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)