20#include <config_features.h>
22#include <officecfg/Office/Common.hxx>
33#include <svx/svxids.hrc>
41#include <fuinsert.hxx>
44#include <drawview.hxx>
45#include <document.hxx>
51#include <com/sun/star/frame/XDispatchProvider.hpp>
52#include <com/sun/star/media/XPlayer.hpp>
53#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
54#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
55#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
56#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
57#include <com/sun/star/uno/Sequence.hxx>
60using namespace css::uno;
67 Size aPageSize = rPage;
68 bool bNegative = aPageSize.
Width() < 0;
78 double fX = aPageSize.
Width() /
static_cast<double>(rSize.
Width());
79 double fY = aPageSize.
Height() /
static_cast<double>(rSize.
Height());
108 const OUString& rFileName,
bool bAsLink,
bool bApi,
114 if ( aMetadata.
read(rGraphic1) )
120 aTransform.
rotate( aRotation );
136 const OUString aBeginUndo(
ScResId(STR_UNDO_DRAGDROP));
142 bAsLink ? rFileName : OUString());
157 MapMode aDestMap( MapUnit::Map100thMM );
158 if ( aSourceMap.
GetMapUnit() == MapUnit::MapPixel && pDrawView )
193 pObj->SetName(
aName);
206 if (bSuccess && bAsLink)
207 pObj->SetGraphicLink( rFileName );
210#if HAVE_FEATURE_AVMEDIA
212static void lcl_InsertMedia(
const OUString& rMediaURL,
bool bApi,
214 const Size& rPrefSize,
bool const bLink )
230 aSize =
Size( 5000, 5000 );
235 aInsertPos.AdjustX( -(aSize.
Width()) );
244 uno::Reference<frame::XModel>
const xModel(
246 bool const bRet = ::avmedia::EmbedMedia(xModel, rMediaURL, realURL);
247 if (!bRet) {
return; }
254 pObj->setURL( realURL,
"" );
255 pView->
InsertObjectAtView( pObj.get(), *pPV, bApi ? SdrInsertFlags::DONTMARK : SdrInsertFlags::NONE );
264 :
FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
269 (pGraphicItem = pReqArgs->
GetItemIfSet( SID_INSERT_GRAPHIC,
true )) )
271 OUString aFileName = pGraphicItem->
GetValue();
273 OUString aFilterName;
275 aFilterName = pFilterItem->GetValue();
277 bool bAsLink =
false;
279 if ( pReqArgs->
GetItemState( FN_PARAM_1,
true, &pItem ) == SfxItemState::SET )
292 ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR);
295 sal_Int16 nSelect = 0;
296 Sequence<OUString> aListBoxEntries {
298 ScResId(STR_ANCHOR_TO_CELL_RESIZE),
303 Any aTemplates(&aListBoxEntries,
cppu::UnoType<
decltype(aListBoxEntries)>::get());
305 xCtrlAcc->setValue(ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
306 ui::dialogs::ListboxControlActions::ADD_ITEMS, aTemplates);
309 xCtrlAcc->setValue(ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
310 ui::dialogs::ListboxControlActions::SET_SELECT_ITEM, aSelectPos);
314 SAL_WARN(
"sc",
"control access failed");
323 OUString aFileName = aDlg.
GetPath();
328 if( bAsLink && officecfg::Office::Common::Misc::ShowLinkWarningDialog::get() )
331 if (aWarnDlg.run() !=
RET_OK)
336 Any aAnchorValue = xCtrlAcc->getValue(
337 ui::dialogs::ExtendedFilePickerElementIds::LISTBOX_IMAGE_ANCHOR,
338 ui::dialogs::ListboxControlActions::GET_SELECTED_ITEM );
340 aAnchorValue >>= sAnchor;
343 if (sAnchor ==
ScResId(STR_ANCHOR_TO_CELL))
345 else if (sAnchor ==
ScResId(STR_ANCHOR_TO_CELL_RESIZE))
347 else if (sAnchor ==
ScResId(STR_ANCHOR_TO_PAGE))
377 FuPoor(rViewSh, pWin, pViewP, pDoc, rReq)
379#if HAVE_FEATURE_AVMEDIA
386 const bool bSizeUnknown = !pSizeItem;
396 bAPI =
aURL.getLength();
400 bool bLink(pLinkItem ? pLinkItem->GetValue() :
true);
401 bool bInsertMedia = bAPI;
409 aPrefSize = pSizeItem->
GetSize();
419 [xDispatchProvider,
aURL, bLink](
const css::uno::Reference<css::media::XPlayer>& rPlayer){
420 css::awt::Size aSize = rPlayer->getPreferredPlayerWindowSize();
429 if (!bIsMediaURL && !bAPI)
static OutputDevice * GetDefaultDevice()
const OUString & GetValue() const
virtual ~FuInsertGraphic() override
FuInsertGraphic(ScTabViewShell &rViewSh, vcl::Window *pWin, ScDrawView *pView, SdrModel *pDoc, SfxRequest &rReq)
Base class for all functions.
ScTabViewShell & rViewShell
VclPtr< vcl::Window > pWindow
static GraphicFilter & GetGraphicFilter()
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
MapMode GetPrefMapMode() const
void SetScaleY(const Fraction &rScaleY)
MapUnit GetMapUnit() const
void SetScaleX(const Fraction &rScaleX)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
SfxObjectShell * GetDocumentShell() const
static void SetCellAnchoredFromPosition(SdrObject &rObj, const ScDocument &rDoc, SCTAB nTab, bool bResizeWithCell)
OUString GetNewGraphicName(tools::Long *pnCounter=nullptr) const
SdrObject * ApplyGraphicToObject(SdrObject &rHitObject, const Graphic &rGraphic, const OUString &rBeginUndoText, const OUString &rFile)
void CalcNormScale(Fraction &rFractX, Fraction &rFractY) const
Point GetInsertPos() const
ScViewData & GetViewData()
ScDrawView * GetScDrawView()
ScDocument & GetDocument() const
bool InsertObjectAtView(SdrObject *pObj, SdrPageView &rPV, SdrInsertFlags nOptions=SdrInsertFlags::NONE)
SdrObject * GetMarkedObjectByIndex(size_t nNum) const
size_t GetMarkedObjectCount() const
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
SdrPage * GetPage() const
SdrModel & getSdrModelFromSdrView() const
SdrPageView * GetSdrPageView() const
SdrModel & GetModel() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
css::uno::Reference< css::frame::XModel3 > GetModel() 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)
SfxFrame & GetFrame() const
SfxViewFrame & GetViewFrame() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
css::uno::Reference< css::ui::dialogs::XFilePickerControlAccess > const & GetFilePickerControlAccess() const
ErrCode GetGraphic(Graphic &) const
OUString const & GetDetectedFilter() const
const Size & GetSize() const
Size LogicToLogic(const Size &rSzSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
Point PixelToLogic(const Point &rDevicePt) const
weld::Window * GetFrameWeld() const
static void lcl_InsertGraphic(const Graphic &rGraphic, const OUString &rFileName, bool bAsLink, bool bApi, ScTabViewShell &rViewSh, const vcl::Window *pWindow, SdrView *pView, ScAnchorType aAnchorType=SCA_CELL)
void ScLimitSizeOnDrawPage(Size &rSize, Point &rPos, const Size &rPage)
#define SAL_WARN(area, stream)
OUString ScResId(TranslateId aId)
Reference< XModel > xModel