[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - cui/source include/sfx2 sw/source

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 11 18:39:14 UTC 2019


 cui/source/dialogs/pastedlg.cxx      |  121 +++++++++++++++++++++++++++++++++++
 cui/source/factory/dlgfact.cxx       |   10 ++
 cui/source/factory/dlgfact.hxx       |    2 
 cui/source/inc/pastedlg.hxx          |   15 ++++
 include/sfx2/sfxdlg.hxx              |    2 
 sw/source/uibase/dochdl/swdtflvr.cxx |   59 +++++++++++++++++
 sw/source/uibase/inc/swdtflvr.hxx    |    7 ++
 sw/source/uibase/shells/basesh.cxx   |   42 ++++++++----
 8 files changed, 247 insertions(+), 11 deletions(-)

New commits:
commit 6193948d171a549a9902d68167f294732e618aaa
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Fri Jun 28 02:30:51 2019 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Thu Jul 11 20:38:25 2019 +0200

    Prepare PasteSpecial for Async-ness (sw, basesh.cxx)
    
    Change-Id: I2653b2131f1b2293a9e3c21f308a0951bbfd3878
    Reviewed-on: https://gerrit.libreoffice.org/75412
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/cui/source/dialogs/pastedlg.cxx b/cui/source/dialogs/pastedlg.cxx
index 33fafa758654..429c2ccbfc98 100644
--- a/cui/source/dialogs/pastedlg.cxx
+++ b/cui/source/dialogs/pastedlg.cxx
@@ -94,6 +94,127 @@ void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString&
     aSupplementMap.insert( std::make_pair( nFormat, rFormatName ) );
 }
 
+void SvPasteObjectDialog::PreGetFormat( const TransferableDataHelper &rHelper )
+{
+    //TODO/LATER: why is the Descriptor never used?!
+    TransferableObjectDescriptor aDesc;
+    if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
+    {
+        (void)const_cast<TransferableDataHelper&>(rHelper).GetTransferableObjectDescriptor(
+                                SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
+    }
+    const DataFlavorExVector* pFormats = &rHelper.GetDataFlavorExVector();
+
+    // create and fill dialog box
+    OUString aSourceName, aTypeName;
+    SvGlobalName aEmptyNm;
+
+    ObjectLB().SetUpdateMode( false );
+
+    DataFlavorExVector::iterator aIter( const_cast<DataFlavorExVector&>(*pFormats).begin() ),
+                                 aEnd( const_cast<DataFlavorExVector&>(*pFormats).end() );
+    while( aIter != aEnd )
+    {
+        SotClipboardFormatId nFormat = (*aIter++).mnSotId;
+
+        std::map< SotClipboardFormatId, OUString >::iterator itName =
+            aSupplementMap.find( nFormat );
+
+        // if there is an "Embed Source" or and "Embedded Object" on the
+        // Clipboard we read the Description and the Source of this object
+        // from an accompanied "Object Descriptor" format on the clipboard
+        // Remember: these formats mostly appear together on the clipboard
+        OUString aName;
+        const OUString* pName = nullptr;
+        if ( itName == aSupplementMap.end() )
+        {
+            SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
+            if ( !aName.isEmpty() )
+                pName = &aName;
+        }
+        else
+        {
+            pName = &(itName->second);
+        }
+
+        if( pName )
+        {
+            aName = *pName;
+
+            if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
+            {
+                if( aDesc.maClassName != aEmptyNm )
+                {
+                    aSourceName = aDesc.maDisplayName;
+
+                    if( aDesc.maClassName == aObjClassName )
+                        aName = aObjName;
+                    else
+                        aName = aTypeName = aDesc.maTypeName;
+                }
+            }
+            else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
+            {
+                continue;
+            }
+            else if( aName.isEmpty() )
+                aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
+
+            // Show RICHTEXT only in case RTF is not present.
+            if (nFormat == SotClipboardFormatId::RICHTEXT)
+            {
+                auto it = std::find_if(pFormats->begin(), pFormats->end(),
+                                       [](const DataFlavorEx& rFlavor) {
+                                           return rFlavor.mnSotId == SotClipboardFormatId::RTF;
+                                       });
+                if (it != pFormats->end())
+                    continue;
+            }
+
+            if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) )
+                ObjectLB().SetEntryData(
+                    ObjectLB().InsertEntry( aName ), reinterpret_cast<void*>(nFormat) );
+        }
+    }
+
+    if( aTypeName.isEmpty() && aSourceName.isEmpty() )
+    {
+        if( aDesc.maClassName != aEmptyNm )
+        {
+            aSourceName = aDesc.maDisplayName;
+            aTypeName = aDesc.maTypeName;
+        }
+
+        if( aTypeName.isEmpty() && aSourceName.isEmpty() )
+        {
+            // global resource from svtools (former so3 resource)
+            aSourceName = SvtResId(STR_UNKNOWN_SOURCE);
+        }
+    }
+
+    ObjectLB().SetUpdateMode( true );
+    SelectObject();
+
+    if( !aSourceName.isEmpty() )
+    {
+        if( !aTypeName.isEmpty() )
+            aTypeName += "\n";
+
+        aTypeName += aSourceName;
+        aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
+    }
+
+    m_pFtObjectSource->SetText( aTypeName );
+}
+
+SotClipboardFormatId SvPasteObjectDialog::GetFormatOnly()
+{
+    if (ObjectLB().GetSelectedEntryData())
+        return static_cast<SotClipboardFormatId>(reinterpret_cast<sal_uLong>(ObjectLB().GetSelectedEntryData()));
+
+    return SotClipboardFormatId::NONE;
+}
+
 SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper)
 {
     //TODO/LATER: why is the Descriptor never used?!
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 10d3724ce658..98f63a2ea043 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -372,6 +372,16 @@ void AbstractPasteDialog_Impl::SetObjName( const SvGlobalName & rClass, const OU
     pDlg->SetObjName( rClass, rObjName );
 }
 
+void AbstractPasteDialog_Impl::PreGetFormat( const TransferableDataHelper& aHelper )
+{
+    pDlg->PreGetFormat( aHelper );
+}
+
+SotClipboardFormatId AbstractPasteDialog_Impl::GetFormatOnly()
+{
+    return pDlg->GetFormatOnly();
+}
+
 SotClipboardFormatId AbstractPasteDialog_Impl::GetFormat( const TransferableDataHelper& aHelper )
 {
     return pDlg->GetFormat( aHelper );
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index 221480ce530a..c33bd15dbd5b 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -409,6 +409,8 @@ public:
     DECL_ABSTDLG_BASE(AbstractPasteDialog_Impl, SvPasteObjectDialog )
     virtual void Insert( SotClipboardFormatId nFormat, const OUString & rFormatName ) override;
     virtual void SetObjName( const SvGlobalName & rClass, const OUString & rObjName ) override;
+    virtual void PreGetFormat( const TransferableDataHelper& aHelper ) override;
+    virtual SotClipboardFormatId GetFormatOnly() override;
     virtual SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper ) override;
 };
 
diff --git a/cui/source/inc/pastedlg.hxx b/cui/source/inc/pastedlg.hxx
index 6ef2572d839b..e8366e0fedaa 100644
--- a/cui/source/inc/pastedlg.hxx
+++ b/cui/source/inc/pastedlg.hxx
@@ -59,6 +59,21 @@ public:
 
     void        Insert( SotClipboardFormatId nFormat, const OUString & rFormatName );
     void        SetObjName( const SvGlobalName & rClass, const OUString & rObjName );
+    /**
+     * @brief PreGetFormat Prepares the dialog for running to get format of paste as a SotClipboardFormatId value by calling GetFormatOnly()
+     * @param aHelper
+     */
+    void        PreGetFormat( const TransferableDataHelper& aHelper);
+    /**
+     * @brief GetFormatOnly Returns a SotClipboardFormatId value. Should be called after actually running the dialog.
+     * @return
+     */
+    SotClipboardFormatId GetFormatOnly();
+    /**
+     * @brief GetFormat Prepares and runs the dialog, and returns a SotClipboardFormatId depending on the RET_OK result
+     * @param aHelper TransferableDataHelper containing the data to be pasted
+     * @return a SotClipboardFormatId value depending on the result of running the dialog
+     */
     SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper);
 };
 
diff --git a/include/sfx2/sfxdlg.hxx b/include/sfx2/sfxdlg.hxx
index e6e8a4046695..6ccdbbb88a63 100644
--- a/include/sfx2/sfxdlg.hxx
+++ b/include/sfx2/sfxdlg.hxx
@@ -103,6 +103,8 @@ protected:
 public:
     virtual void Insert( SotClipboardFormatId nFormat, const rtl::OUString & rFormatName ) = 0;
     virtual void SetObjName( const SvGlobalName & rClass, const rtl::OUString & rObjName ) = 0;
+    virtual void PreGetFormat( const TransferableDataHelper& aHelper ) = 0;
+    virtual SotClipboardFormatId GetFormatOnly() = 0;
     virtual SotClipboardFormatId GetFormat( const TransferableDataHelper& aHelper ) = 0;
 };
 
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index d9f35769d070..3dcce3cf71ed 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -129,6 +129,7 @@
 #include <comphelper/lok.hxx>
 #include <sfx2/classificationhelper.hxx>
 #include <sfx2/sfxresid.hxx>
+#include <sfx2/sfxdlg.hxx>
 
 #include <memory>
 
@@ -2940,6 +2941,64 @@ bool SwTransferable::PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper&
     return SwTransferable::PasteFormat( rSh, rData, SotClipboardFormatId::STRING );
 }
 
+void SwTransferable::PrePasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, VclPtr<SfxAbstractPasteDialog>& pDlg )
+{
+    DataFlavorExVector aFormats( rData.GetDataFlavorExVector() );
+    TransferableObjectDescriptor aDesc;
+
+    SotExchangeDest nDest = SwTransferable::GetSotDestination( rSh );
+
+    SwTransferable *pClipboard = GetSwTransferable( rData );
+    if( pClipboard )
+    {
+        aDesc = pClipboard->m_aObjDesc;
+        const char* pResId;
+        if( pClipboard->m_eBufferType & TransferBufferType::Document )
+            pResId = STR_PRIVATETEXT;
+        else if( pClipboard->m_eBufferType & TransferBufferType::Graphic )
+            pResId = STR_PRIVATEGRAPHIC;
+        else if( pClipboard->m_eBufferType == TransferBufferType::Ole )
+            pResId = STR_PRIVATEOLE;
+        else
+            pResId = nullptr;
+
+        if (pResId)
+        {
+            if (strcmp(STR_PRIVATEOLE, pResId) == 0 || strcmp(STR_PRIVATEGRAPHIC, pResId) == 0)
+            {
+                // add SotClipboardFormatId::EMBED_SOURCE to the formats. This
+                // format display then the private format name.
+                DataFlavorEx aFlavorEx;
+                aFlavorEx.mnSotId = SotClipboardFormatId::EMBED_SOURCE;
+                aFormats.insert( aFormats.begin(), aFlavorEx );
+            }
+            pDlg->SetObjName( pClipboard->m_aObjDesc.maClassName,
+                                SwResId(pResId) );
+            pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, aEmptyOUStr );
+        }
+    }
+    else
+    {
+        if( rData.HasFormat( SotClipboardFormatId::OBJECTDESCRIPTOR ) )
+        {
+            (void)rData.GetTransferableObjectDescriptor(
+                                SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc );
+        }
+
+        if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::EMBED_SOURCE, nDest ))
+            pDlg->Insert( SotClipboardFormatId::EMBED_SOURCE, aEmptyOUStr );
+        if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK_SOURCE, nDest ))
+            pDlg->Insert( SotClipboardFormatId::LINK_SOURCE, aEmptyOUStr );
+    }
+
+    if( SwTransferable::TestAllowedFormat( rData, SotClipboardFormatId::LINK, nDest ))
+        pDlg->Insert( SotClipboardFormatId::LINK, SwResId(STR_DDEFORMAT) );
+
+    for( SotClipboardFormatId* pIds = aPasteSpecialIds; *pIds != SotClipboardFormatId::NONE; ++pIds )
+        if( SwTransferable::TestAllowedFormat( rData, *pIds, nDest ))
+            pDlg->Insert( *pIds, aEmptyOUStr );
+}
+
 bool SwTransferable::PasteSpecial( SwWrtShell& rSh, TransferableDataHelper& rData, SotClipboardFormatId& rFormatUsed )
 {
     bool bRet = false;
diff --git a/sw/source/uibase/inc/swdtflvr.hxx b/sw/source/uibase/inc/swdtflvr.hxx
index 640d972cc631..4896dfd10324 100644
--- a/sw/source/uibase/inc/swdtflvr.hxx
+++ b/sw/source/uibase/inc/swdtflvr.hxx
@@ -32,6 +32,7 @@ class Graphic;
 class ImageMap;
 class INetBookmark;
 class INetImage;
+class SfxAbstractPasteDialog;
 class SwDoc;
 class SwDocFac;
 class SwTextBlocks;
@@ -185,6 +186,12 @@ public:
     static bool IsPasteSpecial( const SwWrtShell& rWrtShell,
                                 const TransferableDataHelper& );
     static bool PasteUnformatted( SwWrtShell& rSh, TransferableDataHelper& );
+    /**
+     * @brief PrePasteSpecial Prepares the given dialog without actually running it
+     * @param rSh
+     * @param rFormatUsed
+     */
+    static void PrePasteSpecial( SwWrtShell& rSh, TransferableDataHelper&, VclPtr<SfxAbstractPasteDialog>& pDlg );
     static bool PasteSpecial( SwWrtShell& rSh, TransferableDataHelper&, SotClipboardFormatId& rFormatUsed );
     static bool PasteFormat( SwWrtShell& rSh, TransferableDataHelper& rData,
                              SotClipboardFormatId nFormat );
diff --git a/sw/source/uibase/shells/basesh.cxx b/sw/source/uibase/shells/basesh.cxx
index f3820f141fa9..8a7f3ca4a2e3 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -380,23 +380,43 @@ void SwBaseShell::ExecClpbrd(SfxRequest &rReq)
                     // destroyed after the paste.
                     SwView* pView = &rView;
                     SotClipboardFormatId nFormatId = SotClipboardFormatId::NONE;
+
                     rReq.Ignore();
                     bIgnore = true;
-                    if(SwTransferable::PasteSpecial( rSh, aDataHelper, nFormatId ))
+                    bool bRet = false;
+
+                    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
+                    VclPtr<SfxAbstractPasteDialog> pDlg(pFact->CreatePasteDialog( &rSh.GetView().GetEditWin() ));
+
+                    // Prepare the dialog
+                    SwTransferable::PrePasteSpecial(rSh, aDataHelper, pDlg);
+                    pDlg->PreGetFormat(aDataHelper);
+
+                    if (pDlg->Execute() == RET_OK)
                     {
-                        SfxViewFrame* pViewFrame = pView->GetViewFrame();
-                        uno::Reference< frame::XDispatchRecorder > xRecorder =
-                            pViewFrame->GetBindings().GetRecorder();
-                        if(xRecorder.is()) {
-                            SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
-                            aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
-                            aReq.Done();
+                        nFormatId = pDlg->GetFormatOnly();
+
+                        if( nFormatId != SotClipboardFormatId::NONE )
+                            bRet = SwTransferable::PasteFormat( rSh, aDataHelper, nFormatId );
+
+                        if (bRet)
+                        {
+                            SfxViewFrame* pViewFrame = pView->GetViewFrame();
+                            uno::Reference< frame::XDispatchRecorder > xRecorder =
+                                pViewFrame->GetBindings().GetRecorder();
+                            if(xRecorder.is()) {
+                                SfxRequest aReq( pViewFrame, SID_CLIPBOARD_FORMAT_ITEMS );
+                                aReq.AppendItem( SfxUInt32Item( SID_CLIPBOARD_FORMAT_ITEMS, static_cast<sal_uInt32>(nFormatId) ) );
+                                aReq.Done();
+                            }
                         }
+
+                        if (rSh.IsFrameSelected() || rSh.IsObjSelected())
+                            rSh.EnterSelFrameMode();
+                        pView->AttrChangedNotify( &rSh );
                     }
 
-                    if (rSh.IsFrameSelected() || rSh.IsObjSelected())
-                        rSh.EnterSelFrameMode();
-                    pView->AttrChangedNotify( &rSh );
+                    pDlg->disposeOnce();
                 }
                 else
                     return;


More information about the Libreoffice-commits mailing list