tdf#41007 sd: Inserting multiple images via the insert dialog and DnD.
Added the behavior of inserting multiple images through the insert dialog, which is similar to DnD. The method for creating a dialog box for inserting images has been extended to allow the selection of multiple images: aDlg.setMultiSelect(true). File selection is now handled as a list instead of a string. Previously, when inserting an image into an area with another image, the new image was inserted next to it, although it was expected to replace the existing image, similar to other modules. In the current patch, when inserting a single image through the paste dialog or DnD into an existing image area, the existing image will be replaced. However, if insert multiple images into an existing image area, the new images will be inserted next to each other. This behavior is consistent with other modules. Change-Id: Ia64634f969e53342dfe2828a67a6ee4277134f7d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/205754 Tested-by: Jenkins Reviewed-by: Roman Kuznetsov <antilibreoffice@gmail.com>
This commit is contained in:
committed by
Roman Kuznetsov
parent
58cd4ec030
commit
4cc4da148a
@@ -85,6 +85,8 @@
|
||||
|
||||
#include <comphelper/lok.hxx>
|
||||
|
||||
#include <com/sun/star/uno/Sequence.hxx>
|
||||
|
||||
using namespace com::sun::star;
|
||||
|
||||
namespace sd {
|
||||
@@ -112,7 +114,8 @@ rtl::Reference<FuPoor> FuInsertGraphic::Create( ViewShell& rViewSh, ::sd::Window
|
||||
|
||||
void FuInsertGraphic::DoExecute( SfxRequest& rReq )
|
||||
{
|
||||
OUString aFileName;
|
||||
css::uno::Sequence < OUString > aFileNames;
|
||||
INetURLObject aURL;
|
||||
Graphic aGraphic;
|
||||
|
||||
bool bAsLink = false;
|
||||
@@ -124,7 +127,8 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq )
|
||||
if ( pArgs &&
|
||||
pArgs->GetItemState( SID_INSERT_GRAPHIC, true, &pItem ) == SfxItemState::SET )
|
||||
{
|
||||
aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
|
||||
OUString aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
|
||||
aFileNames = css::uno::Sequence<OUString>(&aFileName, 1);
|
||||
|
||||
OUString aFilterName;
|
||||
if ( const SfxStringItem* pFilterItem = pArgs->GetItemIfSet( FN_PARAM_FILTER ) )
|
||||
@@ -135,74 +139,83 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq )
|
||||
|
||||
if (comphelper::LibreOfficeKit::isActive())
|
||||
{
|
||||
INetURLObject aURL(aFileName);
|
||||
aURL = INetURLObject(aFileNames[0]);
|
||||
if (INetProtocol::File != aURL.GetProtocol() && HostFilter::isForbidden(aURL.GetHost()))
|
||||
SfxLokHelper::sendNetworkAccessError("insert");
|
||||
}
|
||||
|
||||
nError = GraphicFilter::LoadGraphic( aFileName, aFilterName, aGraphic, &GraphicFilter::GetGraphicFilter() );
|
||||
nError = GraphicFilter::LoadGraphic( aFileNames[0], aFilterName, aGraphic, &GraphicFilter::GetGraphicFilter() );
|
||||
if (nError == ERRCODE_GRFILTER_FORMATERROR)
|
||||
nError = GraphicFilter::LoadGraphic( aFileNames[0], OUString(), aGraphic,
|
||||
&GraphicFilter::GetGraphicFilter() );
|
||||
}
|
||||
else
|
||||
{
|
||||
SvxOpenGraphicDialog aDlg(SdResId(STR_INSERTGRAPHIC), mpWindow ? mpWindow->GetFrameWeld() : nullptr);
|
||||
|
||||
aDlg.setMultiSelect(true);
|
||||
if( aDlg.Execute() != ERRCODE_NONE )
|
||||
return; // cancel dialog
|
||||
|
||||
nError = aDlg.GetGraphic(aGraphic);
|
||||
bAsLink = aDlg.IsAsLink();
|
||||
aFileName = aDlg.GetPath();
|
||||
aFileNames = aDlg.GetSelectedFiles();
|
||||
aDlg.setMultiSelect(false);
|
||||
}
|
||||
|
||||
if( nError == ERRCODE_NONE )
|
||||
for (const auto& aFileName : aFileNames)
|
||||
{
|
||||
GraphicNativeMetadata aMetadata;
|
||||
if ( aMetadata.read(aGraphic) )
|
||||
aURL = INetURLObject(aFileName);
|
||||
nError = GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, aURL );
|
||||
if( nError == ERRCODE_NONE )
|
||||
{
|
||||
const Degree10 aRotation = aMetadata.getRotation();
|
||||
if (aRotation)
|
||||
GraphicNativeMetadata aMetadata;
|
||||
if ( aMetadata.read(aGraphic) )
|
||||
{
|
||||
GraphicNativeTransform aTransform( aGraphic );
|
||||
aTransform.rotate( aRotation );
|
||||
const Degree10 aRotation = aMetadata.getRotation();
|
||||
if (aRotation)
|
||||
{
|
||||
GraphicNativeTransform aTransform( aGraphic );
|
||||
aTransform.rotate( aRotation );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( dynamic_cast< DrawViewShell *>( &mrViewShell ) )
|
||||
{
|
||||
sal_Int8 nAction = DND_ACTION_COPY;
|
||||
SdrObject* pPickObj = nullptr;
|
||||
if (mbReplaceExistingImage)
|
||||
pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() );
|
||||
if (pPickObj)
|
||||
nAction = DND_ACTION_LINK;
|
||||
else
|
||||
if( dynamic_cast< DrawViewShell *>( &mrViewShell ) )
|
||||
{
|
||||
pPickObj = mpView->GetEmptyPresentationObject( PresObjKind::Graphic );
|
||||
sal_Int8 nAction = DND_ACTION_COPY;
|
||||
SdrObject* pPickObj = nullptr;
|
||||
bool bSingleInsert = (aFileNames.getLength() == 1);
|
||||
if (mbReplaceExistingImage || bSingleInsert)
|
||||
pPickObj = mpView->GetSelectedSingleObject( mpView->GetPage() );
|
||||
if (pPickObj)
|
||||
nAction = DND_ACTION_LINK;
|
||||
}
|
||||
|
||||
Point aPos = mpWindow->GetVisibleCenter();
|
||||
SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, nullptr);
|
||||
|
||||
if(pGrafObj && bAsLink )
|
||||
{
|
||||
// really store as link only?
|
||||
if( officecfg::Office::Common::Misc::ShowLinkWarningDialog::get() )
|
||||
else
|
||||
{
|
||||
SvxLinkWarningDialog aWarnDlg(mpWindow->GetFrameWeld(), aFileName);
|
||||
if (aWarnDlg.run() != RET_OK)
|
||||
return; // don't store as link
|
||||
pPickObj = mpView->GetEmptyPresentationObject( PresObjKind::Graphic );
|
||||
if (pPickObj)
|
||||
nAction = DND_ACTION_LINK;
|
||||
}
|
||||
|
||||
// store as link
|
||||
pGrafObj->SetGraphicLink(aFileName);
|
||||
Point aPos = mpWindow->GetVisibleCenter();
|
||||
SdrGrafObj* pGrafObj = mpView->InsertGraphic(aGraphic, nAction, aPos, pPickObj, nullptr);
|
||||
|
||||
if(pGrafObj && bAsLink )
|
||||
{
|
||||
// really store as link only?
|
||||
if( officecfg::Office::Common::Misc::ShowLinkWarningDialog::get() )
|
||||
{
|
||||
SvxLinkWarningDialog aWarnDlg(mpWindow->GetFrameWeld(), aFileName);
|
||||
if (aWarnDlg.run() != RET_OK)
|
||||
return; // don't store as link
|
||||
}
|
||||
|
||||
// store as link
|
||||
pGrafObj->SetGraphicLink(aFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!comphelper::LibreOfficeKit::isActive())
|
||||
{
|
||||
// TODO: enable in LOK, it contains synchronous error window without LOKNotifier
|
||||
SdGRFFilter::HandleGraphicFilterError( nError, GraphicFilter::GetGraphicFilter().GetLastError() );
|
||||
else if (!comphelper::LibreOfficeKit::isActive())
|
||||
{
|
||||
// TODO: enable in LOK, it contains synchronous error window without LOKNotifier
|
||||
SdGRFFilter::HandleGraphicFilterError( nError, GraphicFilter::GetGraphicFilter().GetLastError() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -450,7 +450,23 @@ IMPL_LINK_NOARG(View, DropInsertFileHdl, Timer *, void)
|
||||
{
|
||||
sal_Int8 nTempAction = ( aIter == maDropFileVector.begin() ) ? mnAction : 0;
|
||||
const bool bLink = ( ( nTempAction & DND_ACTION_LINK ) != 0 );
|
||||
SdrGrafObj* pGrafObj = InsertGraphic( aGraphic, nTempAction, maDropPos, nullptr, nullptr );
|
||||
SdrObject* pTargetObj = nullptr;
|
||||
SdrPageView* pPageView = GetSdrPageView();
|
||||
bool bSingleInsert = (maDropFileVector.size() == 1);
|
||||
|
||||
if (pPageView && bSingleInsert)
|
||||
{
|
||||
pTargetObj = PickObj(maDropPos, getHitTolLog(), pPageView);
|
||||
|
||||
if (pTargetObj)
|
||||
{
|
||||
if (dynamic_cast<SdrGrafObj*>(pTargetObj) || pTargetObj->IsClosedObj())
|
||||
nTempAction = DND_ACTION_LINK;
|
||||
else
|
||||
nTempAction = DND_ACTION_MOVE;
|
||||
}
|
||||
}
|
||||
SdrGrafObj* pGrafObj = InsertGraphic( aGraphic, nTempAction, maDropPos, pTargetObj, nullptr );
|
||||
if(pGrafObj && bLink)
|
||||
{
|
||||
pGrafObj->SetGraphicLink( aCurrentDropFile );
|
||||
|
||||
Reference in New Issue
Block a user