[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - include/sfx2 officecfg/registry sfx2/sdi sfx2/source

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 17 16:34:47 UTC 2019


 include/sfx2/sfxsids.hrc                                             |    3 
 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu |   14 +
 sfx2/sdi/docslots.sdi                                                |    5 
 sfx2/sdi/sfx.sdi                                                     |   17 ++
 sfx2/source/appl/appuno.cxx                                          |    4 
 sfx2/source/doc/objserv.cxx                                          |   75 ++++++++++
 6 files changed, 115 insertions(+), 3 deletions(-)

New commits:
commit eeba1b0298296c06392282830f51bdc8d3b502eb
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Thu Dec 6 12:10:13 2018 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Mon Jun 17 18:34:03 2019 +0200

    Redaction: First steps
    
    - Add an uno command to create an empty draw document
    - Create a meta file from the first page of a Writer document
    - Insert meta file to the draw page
    - Doesn't work with normal/default view on big/high-res screens
      because of a bug in the MapModes. Manually setting zoom level to %200
      or "Page Width" (to get rid of the extra space around the actual page)
      works for now as workaround.
    
    Change-Id: I05a987617efdda6690400ef550b81b58b21aa27e
    Reviewed-on: https://gerrit.libreoffice.org/64858
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/69728
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/74172
    Tested-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc
index 80d262e20625..badaedad4d26 100644
--- a/include/sfx2/sfxsids.hrc
+++ b/include/sfx2/sfxsids.hrc
@@ -134,6 +134,7 @@ class SfxDocumentInfoItem;
 #define SID_DIRECTEXPORTDOCASPDF            (SID_SFX_START + 1674)
 #define SID_EXPORTDOCASEPUB                 (SID_SFX_START + 1677)
 #define SID_DIRECTEXPORTDOCASEPUB           (SID_SFX_START + 1678)
+#define SID_REDACTDOC                       (SID_SFX_START + 1732)
 #define SID_UPDATEDOCMODE                   (SID_SFX_START + 1668)
 #define SID_CHECKOUT                        (SID_SFX_START + 512)
 #define SID_CANCELCHECKOUT                  (SID_SFX_START + 513)
@@ -256,7 +257,7 @@ class SfxDocumentInfoItem;
 // not required for preview, but interferes with not-yet-saved embedded data source for main document.
 #define SID_NO_EMBEDDED_DS                  TypedWhichId<SfxBoolItem>(SID_SFX_START + 1731)
 
-//      SID_SFX_free_START                  (SID_SFX_START + 1732)
+//      SID_SFX_free_START                  (SID_SFX_START + 1733)
 //      SID_SFX_free_END                    (SID_SFX_START + 3999)
 
 #define SID_OPEN_NEW_VIEW                   (SID_SFX_START + 520)
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
index c0a1510444eb..de1611cba66a 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu
@@ -4997,6 +4997,20 @@
           <value>1</value>
         </prop>
       </node>
+      <node oor:name=".uno:RedactDoc" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Redact</value>
+        </prop>
+        <prop oor:name="ContextLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Redact</value>
+        </prop>
+        <prop oor:name="TooltipLabel" oor:type="xs:string">
+          <value xml:lang="en-US">Redact Document</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:ConfigureDialog" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">~Customize...</value>
diff --git a/sfx2/sdi/docslots.sdi b/sfx2/sdi/docslots.sdi
index 811467cd94be..5b878b8ff051 100644
--- a/sfx2/sdi/docslots.sdi
+++ b/sfx2/sdi/docslots.sdi
@@ -248,6 +248,11 @@ shell SfxObjectShell
         ExecMethod = ExecFile_Impl ;
         StateMethod = GetState_Impl ;
     ]
+    SID_REDACTDOC
+    [
+        ExecMethod = ExecFile_Impl ;
+        StateMethod = GetState_Impl ;
+    ]
     SID_SIGNATURE
     [
         ExecMethod = ExecFile_Impl;
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 11225f17868e..f8fbcd49d3b5 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -4814,6 +4814,23 @@ SfxVoidItem ExportDirectToEPUB SID_DIRECTEXPORTDOCASEPUB
     GroupId = SfxGroupId::Document;
 ]
 
+SfxVoidItem RedactDoc SID_REDACTDOC
+(SfxStringItem URL SID_FILE_NAME, SfxStringItem FilterName SID_FILTER_NAME)
+[
+    AutoUpdate = FALSE,
+    FastCall = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = TRUE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    ToolBoxConfig = TRUE,
+    GroupId = SfxGroupId::Document;
+]
+
 SfxImageItem ImageOrientation SID_IMAGE_ORIENTATION
 
 [
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
index 2ce0f060184a..57bc154ad891 100644
--- a/sfx2/source/appl/appuno.cxx
+++ b/sfx2/source/appl/appuno.cxx
@@ -175,7 +175,7 @@ static bool isMediaDescriptor( sal_uInt16 nSlotId )
              nSlotId == SID_SAVETO || nSlotId == SID_SAVEACOPY ||
              nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
              nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB ||
-             nSlotId == SID_SAVEACOPYITEM);
+             nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPYITEM);
 }
 
 void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::PropertyValue>& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot )
@@ -1338,7 +1338,7 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
     if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC ||  nSlotId == SID_SAVEDOC ||
          nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
          nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB ||
-         nSlotId == SID_SAVEACOPY )
+         nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPY )
     {
         const SfxPoolItem *pItem=nullptr;
         if ( rSet.GetItemState( SID_COMPONENTDATA, false, &pItem ) == SfxItemState::SET )
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index cb7bbfd75d75..f2ca4cbdebcc 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -62,8 +62,11 @@
 #include <unotools/useroptions.hxx>
 #include <unotools/saveopt.hxx>
 #include <svtools/asynclink.hxx>
+#include <svtools/DocumentToGraphicRenderer.hxx>
+#include <vcl/gdimtf.hxx>
 #include <comphelper/fileformat.h>
 #include <comphelper/documentconstants.hxx>
+#include <comphelper/propertyvalue.hxx>
 #include <comphelper/storagehelper.hxx>
 #include <tools/link.hxx>
 
@@ -99,6 +102,11 @@
 #include <com/sun/star/embed/XTransactedObject.hpp>
 #include <com/sun/star/util/XCloneable.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/text/XPageCursor.hpp>
+#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
+
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 
 #include <guisaveas.hxx>
 #include <saveastemplatedlg.hxx>
@@ -107,6 +115,8 @@
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/streamwrap.hxx>
 
+#include <svx/unoshape.hxx>
+
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::uno;
@@ -529,6 +539,70 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
             return;
         }
 
+        case SID_REDACTDOC:
+        {
+            css::uno::Reference<css::frame::XModel> xModel = GetModel();
+            if(!xModel.is())
+                return;
+
+            uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
+                        xModel->getCurrentController(), uno::UNO_QUERY);
+            if(!xTextViewCursorSupplier.is())
+                return;
+
+            uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
+                                                      uno::UNO_QUERY);
+            if(!xCursor.is())
+                return;
+
+            uno::Reference< lang::XComponent > xSourceDoc( xModel );
+            DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false);
+
+            // Only take the first page for now
+            sal_Int16 nPage = 1;
+
+            ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
+            ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage);
+            // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor.
+            ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23);
+
+            Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT, true);
+            auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile());
+
+            // Set preferred map unit and size on the metafile, so the Shape size
+            // will be correct in MM.
+            MapMode aMapMode;
+            aMapMode.SetMapUnit(MapUnit::Map100thMM);
+            rGDIMetaFile.SetPrefMapMode(aMapMode);
+            rGDIMetaFile.SetPrefSize(aLogic);
+
+            // Create an empty Draw component.
+            uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
+            uno::Reference<frame::XComponentLoader> xComponentLoader(xDesktop, uno::UNO_QUERY);
+            uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});
+
+            // Access the draw pages
+            uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
+            uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
+            uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
+
+            uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic();
+
+            // Create and insert the shape
+            uno::Reference<css::lang::XMultiServiceFactory> xFactory(xComponent, uno::UNO_QUERY);
+            uno::Reference<drawing::XShape> xShape(
+                    xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
+            uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
+            xShapeProperySet->setPropertyValue("Graphic", uno::Any( xGraph ));
+
+            // Set size and position
+            xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) );
+
+            xPage->add(xShape);
+
+            return;
+        }
+
         // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
         case SID_EXPORTDOCASPDF:
         case SID_DIRECTEXPORTDOCASPDF:
@@ -1016,6 +1090,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
             case SID_DIRECTEXPORTDOCASPDF:
             case SID_EXPORTDOCASEPUB:
             case SID_DIRECTEXPORTDOCASEPUB:
+            case SID_REDACTDOC:
             {
                 break;
             }


More information about the Libreoffice-commits mailing list