tdf#157363 add HTML format when pasting into draw text

adds HTML to paste(special) in draw text in impress/draw/calc/writer

Change-Id: Iaede82e1b3d48be362b70bd631e7f912b02b9822
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158659
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
This commit is contained in:
Oliver Specht 2023-10-30 13:26:49 +01:00 committed by Thorsten Behrens
parent 7924d8fc27
commit 87be89ac27
13 changed files with 84 additions and 21 deletions

View File

@ -849,9 +849,9 @@ EditSelection EditEngine::InsertText(const EditTextObject& rTextObject, const Ed
EditSelection EditEngine::InsertText(
uno::Reference<datatransfer::XTransferable > const & rxDataObj,
const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial)
const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial, SotClipboardFormatId format)
{
return pImpEditEngine->PasteText(rxDataObj, rBaseURL, rPaM, bUseSpecial);
return pImpEditEngine->PasteText(rxDataObj, rBaseURL, rPaM, bUseSpecial, format);
}
EditPaM EditEngine::EndOfWord(const EditPaM& rPaM)

View File

@ -685,10 +685,10 @@ void EditView::Paste()
pImpEditView->Paste( aClipBoard );
}
void EditView::PasteSpecial()
void EditView::PasteSpecial(SotClipboardFormatId format)
{
Reference<css::datatransfer::clipboard::XClipboard> aClipBoard(GetClipboard());
pImpEditView->Paste(aClipBoard, true );
pImpEditView->Paste(aClipBoard, true, format );
}
Point EditView::GetWindowPosTopLeft( sal_Int32 nParagraph )

View File

@ -1946,7 +1946,7 @@ void ImpEditView::CutCopy( css::uno::Reference< css::datatransfer::clipboard::XC
}
}
void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial )
void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial, SotClipboardFormatId format)
{
if ( !rxClipboard.is() )
return;
@ -2006,7 +2006,7 @@ void ImpEditView::Paste( css::uno::Reference< css::datatransfer::clipboard::XCli
// paragraphs. Collect and broadcast when done instead.
aSel = pEditEngine->InsertText(
xDataObj, OUString(), aSel.Min(),
bUseSpecial && pEditEngine->GetInternalEditStatus().AllowPasteSpecial());
bUseSpecial && pEditEngine->GetInternalEditStatus().AllowPasteSpecial(), format);
}
aPasteOrDropInfos.nEndPara = pEditEngine->GetEditDoc().GetPos( aSel.Max().GetNode() );

View File

@ -377,7 +377,7 @@ public:
bool Command(const CommandEvent& rCEvt);
void CutCopy( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bCut );
void Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial = false );
void Paste( css::uno::Reference< css::datatransfer::clipboard::XClipboard > const & rxClipboard, bool bUseSpecial = false, SotClipboardFormatId format = SotClipboardFormatId::NONE);
void SetVisDocStartPos( const Point& rPos ) { aVisDocStartPos = rPos; }
@ -644,7 +644,7 @@ private:
std::unique_ptr<EditTextObject>
CreateTextObject(EditSelection aSelection, SfxItemPool*, bool bAllowBigObjects = false, sal_Int32 nBigObjStart = 0);
EditSelection InsertTextObject( const EditTextObject&, EditPaM aPaM );
EditSelection PasteText( css::uno::Reference< css::datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial );
EditSelection PasteText( css::uno::Reference< css::datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial, SotClipboardFormatId format = SotClipboardFormatId::NONE);
void CheckPageOverflow();

View File

@ -30,6 +30,7 @@
#include "eeobj.hxx"
#include <editeng/txtrange.hxx>
#include <sfx2/app.hxx>
#include <sfx2/mieclip.hxx>
#include <svtools/colorcfg.hxx>
#include <svl/ctloptions.hxx>
#include <unotools/securityoptions.hxx>
@ -3879,7 +3880,7 @@ uno::Reference< datatransfer::XTransferable > ImpEditEngine::CreateTransferable(
return pDataObj;
}
EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial )
EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransferable > const & rxDataObj, const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial, SotClipboardFormatId format)
{
EditSelection aNewSelection( rPaM );
@ -3893,7 +3894,7 @@ EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransfera
{
// XML
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT, aFlavor );
if ( rxDataObj->isDataFlavorSupported( aFlavor ) )
if ( rxDataObj->isDataFlavorSupported( aFlavor ) && (SotClipboardFormatId::NONE == format || SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT == format))
{
try
{
@ -3921,7 +3922,7 @@ EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransfera
SotExchange::GetFormatDataFlavor( SotClipboardFormatId::RICHTEXT, aFlavorRichtext );
bool bRtfSupported = rxDataObj->isDataFlavorSupported( aFlavor );
bool bRichtextSupported = rxDataObj->isDataFlavorSupported( aFlavorRichtext );
if ( bRtfSupported || bRichtextSupported )
if ( (bRtfSupported || bRichtextSupported) && (SotClipboardFormatId::NONE == format || SotClipboardFormatId::RICHTEXT == format || SotClipboardFormatId::RTF == format))
{
if(bRichtextSupported)
{
@ -3943,6 +3944,31 @@ EditSelection ImpEditEngine::PasteText( uno::Reference< datatransfer::XTransfera
}
}
}
if (!bDone) {
// HTML
SotExchange::GetFormatDataFlavor(SotClipboardFormatId::HTML_SIMPLE, aFlavor);
bool bHtmlSupported = rxDataObj->isDataFlavorSupported(aFlavor);
if (bHtmlSupported && (SotClipboardFormatId::NONE == format || SotClipboardFormatId::HTML_SIMPLE == format)) {
MSE40HTMLClipFormatObj aMSE40HTMLClipFormatObj;
try
{
uno::Any aData = rxDataObj->getTransferData(aFlavor);
uno::Sequence< sal_Int8 > aSeq;
aData >>= aSeq;
{
SvMemoryStream aHtmlStream(aSeq.getArray(), aSeq.getLength(), StreamMode::READ);
SvStream* pHtmlStream = aMSE40HTMLClipFormatObj.IsValid(aHtmlStream);
if (pHtmlStream != nullptr) {
aNewSelection = Read(*pHtmlStream, rBaseURL, EETextFormat::Html, rPaM);
}
}
bDone = true;
}
catch (const css::uno::Exception&)
{
}
}
}
}
if ( !bDone )
{

View File

@ -667,12 +667,12 @@ void OutlinerView::Cut()
}
}
void OutlinerView::PasteSpecial()
void OutlinerView::PasteSpecial(SotClipboardFormatId format)
{
Paste( true );
Paste( true, format );
}
void OutlinerView::Paste( bool bUseSpecial )
void OutlinerView::Paste( bool bUseSpecial, SotClipboardFormatId format)
{
if ( ImpCalcSelectedPages( false ) && !pOwner->ImpCanDeleteSelectedPages( this ) )
return;
@ -683,7 +683,7 @@ void OutlinerView::Paste( bool bUseSpecial )
pOwner->bPasting = true;
if ( bUseSpecial )
pEditView->PasteSpecial();
pEditView->PasteSpecial(format);
else
pEditView->Paste();

View File

@ -30,6 +30,7 @@
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
#include <sot/formats.hxx>
#include <svl/typedwhich.hxx>
#include <editeng/editdata.hxx>
#include <editeng/editstat.hxx>
@ -154,7 +155,8 @@ public:
EditSelection InsertText(
css::uno::Reference<css::datatransfer::XTransferable > const & rxDataObj,
const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial);
const OUString& rBaseURL, const EditPaM& rPaM, bool bUseSpecial,
SotClipboardFormatId format = SotClipboardFormatId::NONE);
private:
std::unique_ptr<ImpEditEngine> pImpEditEngine;

View File

@ -24,6 +24,7 @@
#include <com/sun/star/i18n/WordType.hpp>
#include <i18nlangtag/lang.h>
#include <sot/formats.hxx>
#include <tools/color.hxx>
#include <tools/gen.hxx>
#include <comphelper/errcode.hxx>
@ -258,7 +259,7 @@ public:
void Cut();
void Copy();
void Paste();
void PasteSpecial();
void PasteSpecial(SotClipboardFormatId format = SotClipboardFormatId::NONE);
void Undo();
void Redo();

View File

@ -19,6 +19,7 @@
#ifndef INCLUDED_EDITENG_OUTLINER_HXX
#define INCLUDED_EDITENG_OUTLINER_HXX
#include <sot/formats.hxx>
#include <editeng/editdata.hxx>
#include <editeng/editstat.hxx>
#include <editeng/overflowingtxt.hxx>
@ -264,8 +265,8 @@ public:
void Cut();
void Copy();
void Paste( bool bUseSpecial = false );
void PasteSpecial();
void Paste( bool bUseSpecial = false, SotClipboardFormatId format = SotClipboardFormatId::NONE );
void PasteSpecial(SotClipboardFormatId format = SotClipboardFormatId::NONE);
void SetStyleSheet(const OUString& rStyleName);

View File

@ -105,6 +105,7 @@ void ScDrawTextObjectBar::ExecutePasteContents( SfxRequest & /* rReq */ )
pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
pDlg->Insert( SotClipboardFormatId::RTF, OUString() );
pDlg->Insert( SotClipboardFormatId::RICHTEXT, OUString() );
pDlg->Insert(SotClipboardFormatId::HTML_SIMPLE, OUString());
TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard( mrViewData.GetActiveWin() ) );
@ -117,7 +118,7 @@ void ScDrawTextObjectBar::ExecutePasteContents( SfxRequest & /* rReq */ )
if (nFormat == SotClipboardFormatId::STRING)
pOutView->Paste();
else
pOutView->PasteSpecial();
pOutView->PasteSpecial(nFormat);
}
}

View File

@ -225,6 +225,7 @@ void FuInsertClipboard::DoExecute( SfxRequest& )
pDlg->Insert( SotClipboardFormatId::NETSCAPE_BOOKMARK, OUString() );
pDlg->Insert( SotClipboardFormatId::STRING, OUString() );
pDlg->Insert( SotClipboardFormatId::HTML, OUString() );
pDlg->Insert(SotClipboardFormatId::HTML_SIMPLE, OUString());
pDlg->Insert( SotClipboardFormatId::RTF, OUString() );
pDlg->Insert( SotClipboardFormatId::RICHTEXT, OUString() );
pDlg->Insert( SotClipboardFormatId::EDITENGINE_ODF_TEXT_FLAT, OUString() );

View File

@ -1491,6 +1491,36 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
}
}
}
bool bIsHtmlSimple = CHECK_FORMAT_TRANS(SotClipboardFormatId::HTML_SIMPLE);
if (bIsHtmlSimple)
{
::tools::SvRef<SotTempStream> xStm;
if (aDataHelper.GetSotStorageStream(SotClipboardFormatId::HTML_SIMPLE, xStm))
{
xStm->Seek(0);
OutlinerView* pOLV = GetTextEditOutlinerView();
if (pOLV)
{
::tools::Rectangle aRect(pOLV->GetOutputArea());
Point aPos(pOLV->GetWindow()->PixelToLogic(maDropPos));
if (aRect.Contains(aPos) || (!bDrag && IsTextEdit()))
{
// mba: clipboard always must contain absolute URLs (could be from alien source)
pOLV->Read(*xStm, EETextFormat::Html, mpDocSh->GetHeaderAttributes());
bReturn = true;
}
}
if (!bReturn)
// mba: clipboard always must contain absolute URLs (could be from alien source)
bReturn = SdrView::Paste(*xStm, EETextFormat::Html, maDropPos, pPage, nPasteOptions);
}
}
}
if(!bReturn && CHECK_FORMAT_TRANS(SotClipboardFormatId::FILE_LIST))

View File

@ -1082,6 +1082,7 @@ void SwDrawTextShell::ExecClpbrd(SfxRequest const &rReq)
pDlg->Insert(SotClipboardFormatId::STRING, OUString());
pDlg->Insert(SotClipboardFormatId::RTF, OUString());
pDlg->Insert(SotClipboardFormatId::RICHTEXT, OUString());
pDlg->Insert(SotClipboardFormatId::HTML_SIMPLE, OUString());
TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&GetView().GetEditWin()));
SotClipboardFormatId nFormat = pDlg->GetFormat(aDataHelper.GetTransferable());
@ -1091,7 +1092,7 @@ void SwDrawTextShell::ExecClpbrd(SfxRequest const &rReq)
if (nFormat == SotClipboardFormatId::STRING)
pOLV->Paste();
else
pOLV->PasteSpecial();
pOLV->PasteSpecial(nFormat);
}
break;