Resolves tdf#130436: Crash on redaction without Draw

Change-Id: Iaa418e9ad5c6e9ba1892cbb428a8a381f52c4246
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97458
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index e845c51..c5e61d9 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -208,6 +208,7 @@
#define STR_REDACTION_JSON_FILE_FILTER          NC_("STR_REDACTION_JSON_FILE_FILTER", "Target Set (*.json)")
#define STR_REDACTION_EDIT_TARGET               NC_("STR_REDACTION_EDIT_TARGET", "Edit Target")
#define STR_REDACTION_TARGET_ADD_ERROR          NC_("STR_REDACTION_TARGET_ADD_ERROR", "An error occurred while adding new target. Please report this incident.")
#define STR_REDACTION_NO_DRAW_WARNING           NC_("STR_REDACTION_NO_DRAW_WARNING", "Draw module is needed for redaction. Please make sure you have LibreOffice Draw installed and working correctly.")

#define STR_SFX_FILEDLG_ACTUALVERSION           NC_("STR_SFX_FILEDLG_ACTUALVERSION", "Current version")
#define STR_SFX_EXPLORERFILE_EXPORT             NC_("STR_SFX_EXPLORERFILE_EXPORT", "Export")
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 85406b9..349cac3 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -51,6 +51,7 @@
#include <comphelper/string.hxx>
#include <basic/sbxcore.hxx>
#include <basic/sberrors.hxx>
#include <unotools/moduleoptions.hxx>
#include <unotools/saveopt.hxx>
#include <svtools/DocumentToGraphicRenderer.hxx>
#include <vcl/gdimtf.hxx>
@@ -601,6 +602,18 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)

        case SID_AUTOREDACTDOC:
        {
            // Actual redaction takes place on a newly generated Draw document
            if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
            {
                std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
                    pDialogParent, VclMessageType::Warning, VclButtonsType::Ok,
                    SfxResId(STR_REDACTION_NO_DRAW_WARNING)));

                xBox->run();

                return;
            }

            SfxAutoRedactDialog aDlg(pDialogParent);
            sal_Int16 nResult = aDlg.run();

@@ -625,6 +638,18 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)

            uno::Reference< lang::XComponent > xSourceDoc( xModel );

            // Actual redaction takes place on a newly generated Draw document
            if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
            {
                std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
                    pDialogParent, VclMessageType::Warning, VclButtonsType::Ok,
                    SfxResId(STR_REDACTION_NO_DRAW_WARNING)));

                xBox->run();

                return;
            }

            DocumentToGraphicRenderer aRenderer(xSourceDoc, false);

            // Get the page margins of the original doc
@@ -645,6 +670,13 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
            uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
            uno::Reference<lang::XComponent> xComponent = xDesktop->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});

            if (!xComponent.is())
            {
                SAL_WARN("sfx.doc", "SID_REDACTDOC: Failed to load new draw component. loadComponentFromURL returned an empty reference.");

                return;
            }

            // Add the doc pages to the new draw document
            SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, aPageMargins, aRedactionTargets, bIsAutoRedact);