weld SwMMResultEmailDialog

Change-Id: Ib12455751074bbd818cc2da0c813fe984d887571
Reviewed-on: https://gerrit.libreoffice.org/61920
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/sw/inc/swabstdlg.hxx b/sw/inc/swabstdlg.hxx
index ea8a27f..59f7e12 100644
--- a/sw/inc/swabstdlg.hxx
+++ b/sw/inc/swabstdlg.hxx
@@ -499,7 +499,7 @@ public:

    virtual void ExecuteMMResultSaveDialog(weld::Window* pParent) = 0;
    virtual void ExecuteMMResultPrintDialog(weld::Window* pParent) = 0;
    virtual void ExecuteMMResultEmailDialog() = 0;
    virtual void ExecuteMMResultEmailDialog(weld::Window* pParent) = 0;

protected:
    ~SwAbstractDialogFactory() {}
diff --git a/sw/source/ui/dbui/mmresultdialogs.cxx b/sw/source/ui/dbui/mmresultdialogs.cxx
index d4dc1b1..fe95b26 100644
--- a/sw/source/ui/dbui/mmresultdialogs.cxx
+++ b/sw/source/ui/dbui/mmresultdialogs.cxx
@@ -227,7 +227,7 @@ SwMMResultSaveDialog::SwMMResultSaveDialog(weld::Window* pParent)
    m_xSaveAsOneRB->connect_toggled(aLink);
    m_xSaveIndividualRB->connect_toggled(aLink);
    m_xFromRB->connect_toggled(aLink);
    // m_pSaveAsOneRB is the default, so disable m_pFromNF and m_pToNF initially.
    // m_pSaveAsOneRB is the default, so disable m_xFromNF and m_xToNF initially.
    aLink.Call(*m_xSaveAsOneRB);
    SwView* pView = ::GetActiveView();
    std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
@@ -264,7 +264,7 @@ SwMMResultPrintDialog::SwMMResultPrintDialog(weld::Window* pParent)
    Link<weld::ToggleButton&,void> aLink = LINK(this, SwMMResultPrintDialog, DocumentSelectionHdl_Impl);
    m_xPrintAllRB->connect_toggled(aLink);
    m_xFromRB->connect_toggled(aLink);
    // m_pPrintAllRB is the default, so disable m_pFromNF and m_pToNF initially.
    // m_pPrintAllRB is the default, so disable m_xFromNF and m_xToNF initially.
    aLink.Call(*m_xPrintAllRB);

    m_xOKButton->connect_clicked(LINK(this, SwMMResultPrintDialog, PrintHdl_Impl));
@@ -276,67 +276,43 @@ SwMMResultPrintDialog::~SwMMResultPrintDialog()
{
}

SwMMResultEmailDialog::SwMMResultEmailDialog()
    : SfxModalDialog(nullptr, "MMResultEmailDialog", "modules/swriter/ui/mmresultemaildialog.ui"),
     m_sConfigureMail(SwResId(ST_CONFIGUREMAIL))
SwMMResultEmailDialog::SwMMResultEmailDialog(weld::Window* pParent)
    : SfxDialogController(pParent, "modules/swriter/ui/mmresultemaildialog.ui", "MMResultEmailDialog")
    , m_sConfigureMail(SwResId(ST_CONFIGUREMAIL))
    , m_xMailToFT(m_xBuilder->weld_label("mailtoft"))
    , m_xMailToLB(m_xBuilder->weld_combo_box("mailto"))
    , m_xCopyToPB(m_xBuilder->weld_button("copyto"))
    , m_xSubjectFT(m_xBuilder->weld_label("subjectft"))
    , m_xSubjectED(m_xBuilder->weld_entry("subject"))
    , m_xSendAsFT(m_xBuilder->weld_label("sendasft"))
    , m_xSendAsLB(m_xBuilder->weld_combo_box("sendas"))
    , m_xSendAsPB(m_xBuilder->weld_button("sendassettings"))
    , m_xAttachmentGroup(m_xBuilder->weld_widget("attachgroup"))
    , m_xAttachmentED(m_xBuilder->weld_entry("attach"))
    , m_xSendAllRB(m_xBuilder->weld_radio_button("sendallrb"))
    , m_xFromRB(m_xBuilder->weld_radio_button("fromrb"))
    , m_xFromNF(m_xBuilder->weld_spin_button("from"))
    , m_xToFT(m_xBuilder->weld_label("toft"))
    , m_xToNF(m_xBuilder->weld_spin_button("to"))
    , m_xOKButton(m_xBuilder->weld_button("ok"))
{
    get(m_pMailToFT, "mailtoft");
    get(m_pMailToLB, "mailto");
    get(m_pCopyToPB, "copyto");
    get(m_pSubjectFT, "subjectft");
    get(m_pSubjectED, "subject");
    get(m_pSendAsFT, "sendasft");
    get(m_pSendAsLB, "sendas");
    get(m_pAttachmentGroup, "attachgroup");
    get(m_pAttachmentED, "attach");
    get(m_pSendAsPB, "sendassettings");
    get(m_pSendAllRB, "sendallrb");
    get(m_pFromRB, "fromrb");
    get(m_pFromNF, "from-nospin");
    get(m_pToFT, "toft");
    get(m_pToNF, "to-nospin");
    get(m_pOKButton, "ok");
    m_xCopyToPB->connect_clicked(LINK(this, SwMMResultEmailDialog, CopyToHdl_Impl));
    m_xSendAsPB->connect_clicked(LINK(this, SwMMResultEmailDialog, SendAsHdl_Impl));
    m_xSendAsLB->connect_changed(LINK(this, SwMMResultEmailDialog, SendTypeHdl_Impl));

    m_pCopyToPB->SetClickHdl(LINK(this, SwMMResultEmailDialog, CopyToHdl_Impl));
    m_pSendAsPB->SetClickHdl(LINK(this, SwMMResultEmailDialog, SendAsHdl_Impl));
    m_pSendAsLB->SetSelectHdl(LINK(this, SwMMResultEmailDialog, SendTypeHdl_Impl));
    Link<weld::ToggleButton&,void> aLink = LINK(this, SwMMResultEmailDialog, DocumentSelectionHdl_Impl);
    m_xSendAllRB->connect_toggled(aLink);
    m_xFromRB->connect_toggled(aLink);
    // m_xSendAllRB is the default, so disable m_xFromNF and m_xToNF initially.
    aLink.Call(*m_xSendAllRB);

    Link<Button*,void> aLink = LINK(this, SwMMResultEmailDialog, DocumentSelectionHdl_Impl);
    m_pSendAllRB->SetClickHdl(aLink);
    m_pFromRB->SetClickHdl(aLink);
    // m_pSendAllRB is the default, so disable m_pFromNF and m_pToNF initially.
    aLink.Call(m_pSendAllRB);

    m_pOKButton->SetClickHdl(LINK(this, SwMMResultEmailDialog, SendDocumentsHdl_Impl));
    m_xOKButton->connect_clicked(LINK(this, SwMMResultEmailDialog, SendDocumentsHdl_Impl));

    FillInEmailSettings();
}

SwMMResultEmailDialog::~SwMMResultEmailDialog()
{
    disposeOnce();
}

void SwMMResultEmailDialog::dispose()
{
    m_pMailToFT.clear();
    m_pMailToLB.clear();
    m_pCopyToPB.clear();
    m_pSubjectFT.clear();
    m_pSubjectED.clear();
    m_pSendAsFT.clear();
    m_pSendAsLB.clear();
    m_pAttachmentGroup.clear();
    m_pAttachmentED.clear();
    m_pSendAllRB.clear();
    m_pFromRB.clear();
    m_pFromNF.clear();
    m_pToFT.clear();
    m_pToNF.clear();
    m_pOKButton.clear();
    m_pSendAsPB.clear();

    SfxModalDialog::dispose();
}

void SwMMResultPrintDialog::FillInPrinterSettings()
@@ -387,21 +363,20 @@ void SwMMResultEmailDialog::FillInEmailSettings()
        if (pDocShell->HasName())
        {
            INetURLObject aTmp(pDocShell->GetMedium()->GetName());
            m_pAttachmentED->SetText(aTmp.getName(
            m_xAttachmentED->set_text(aTmp.getName(
                    INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::WithCharset ));
        }
    }

    if (m_pAttachmentED->GetText().isEmpty())
    if (m_xAttachmentED->get_text().isEmpty())
    {
        OUString sAttach = "." + lcl_GetExtensionForDocType(
                    reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectedEntryData()));
        m_pAttachmentED->SetText(sAttach);
        OUString sAttach = "." + lcl_GetExtensionForDocType(m_xSendAsLB->get_active_id().toUInt32());
        m_xAttachmentED->set_text(sAttach);

    }

    //fill mail address ListBox
    if (m_pMailToLB->GetEntryCount())
    if (m_xMailToLB->get_count())
        return;

    //select first column
@@ -413,50 +388,50 @@ void SwMMResultEmailDialog::FillInEmailSettings()
        aFields = xColAccess->getElementNames();
    const OUString* pFields = aFields.getConstArray();
    for (sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
        m_pMailToLB->InsertEntry(pFields[nField]);
        m_xMailToLB->append_text(pFields[nField]);

    m_pMailToLB->SelectEntryPos(0);
    m_xMailToLB->set_active(0);
    // then select the right one - may not be available
    const std::vector<std::pair<OUString, int>>& rHeaders = xConfigItem->GetDefaultAddressHeaders();
    OUString sEMailColumn = rHeaders[MM_PART_E_MAIL].first;
    Sequence< OUString> aAssignment = xConfigItem->GetColumnAssignment(xConfigItem->GetCurrentDBData());
    if (aAssignment.getLength() > MM_PART_E_MAIL && !aAssignment[MM_PART_E_MAIL].isEmpty())
        sEMailColumn = aAssignment[MM_PART_E_MAIL];
    m_pMailToLB->SelectEntry(sEMailColumn);
    m_xMailToLB->set_active_text(sEMailColumn);

    // HTML format pre-selected
    m_pSendAsLB->SelectEntryPos(3);
    SendTypeHdl_Impl(*m_pSendAsLB);
    m_xSendAsLB->set_active(3);
    SendTypeHdl_Impl(*m_xSendAsLB);

}

IMPL_LINK(SwMMResultSaveDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, rButton, void)
IMPL_LINK_NOARG(SwMMResultSaveDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
{
    bool bEnableFromTo = &rButton == m_xFromRB.get();
    bool bEnableFromTo = m_xFromRB->get_active();
    m_xFromNF->set_sensitive(bEnableFromTo);
    m_xToFT->set_sensitive(bEnableFromTo);
    m_xToNF->set_sensitive(bEnableFromTo);
}

IMPL_LINK(SwMMResultPrintDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, rButton, void)
IMPL_LINK_NOARG(SwMMResultPrintDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
{
    bool bEnableFromTo = &rButton == m_xFromRB.get();
    bool bEnableFromTo = m_xFromRB->get_active();
    m_xFromNF->set_sensitive(bEnableFromTo);
    m_xToFT->set_sensitive(bEnableFromTo);
    m_xToNF->set_sensitive(bEnableFromTo);
}

IMPL_LINK(SwMMResultEmailDialog, DocumentSelectionHdl_Impl, Button*, pButton, void)
IMPL_LINK_NOARG(SwMMResultEmailDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
{
    bool bEnableFromTo = pButton == m_pFromRB;
    m_pFromNF->Enable(bEnableFromTo);
    m_pToFT->Enable(bEnableFromTo);
    m_pToNF->Enable(bEnableFromTo);
    bool bEnableFromTo = m_xFromRB->get_active();
    m_xFromNF->set_sensitive(bEnableFromTo);
    m_xToFT->set_sensitive(bEnableFromTo);
    m_xToNF->set_sensitive(bEnableFromTo);
}

IMPL_LINK_NOARG(SwMMResultEmailDialog, CopyToHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SwMMResultEmailDialog, CopyToHdl_Impl, weld::Button&, void)
{
    SwCopyToDialog aDlg(GetFrameWeld());
    SwCopyToDialog aDlg(m_xDialog.get());
    aDlg.SetCC(m_sCC );
    aDlg.SetBCC(m_sBCC);
    if (aDlg.run() == RET_OK)
@@ -511,15 +486,6 @@ int documentEndPageNumber(SwMailMergeConfigItem* pConfigItem, int document, bool
    return page;
}

void endDialog(Button* pButton)
{
    vcl::Window* pParent = getNonLayoutParent(pButton);
    Dialog *pDialog = dynamic_cast<Dialog*>(pParent);

    if (pDialog && pDialog->IsInExecute())
        pDialog->EndDialog(RET_OK);
}

} // anonymous namespace

IMPL_LINK_NOARG(SwMMResultSaveDialog, SaveOutputHdl_Impl, weld::Button&, void)
@@ -824,16 +790,16 @@ IMPL_LINK_NOARG(SwMMResultPrintDialog, PrinterSetupHdl_Impl, weld::Button&, void
        m_pTempPrinter->Setup(m_xDialog.get());
}

IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, ListBox&, rBox, void)
IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, weld::ComboBox&, rBox, void)
{
    sal_uLong nDocType = reinterpret_cast<sal_uLong>(rBox.GetSelectedEntryData());
    auto nDocType = rBox.get_active_id().toUInt32();
    bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
    m_pSendAsPB->Enable( bEnable );
    m_pAttachmentGroup->Enable( bEnable );
    m_xSendAsPB->set_sensitive(bEnable);
    m_xAttachmentGroup->set_sensitive(bEnable);
    if(bEnable)
    {
        //add the correct extension
        OUString sAttach(m_pAttachmentED->GetText());
        OUString sAttach(m_xAttachmentED->get_text());
        //do nothing if the user has removed the name - the warning will come early enough
        if (!sAttach.isEmpty())
        {
@@ -844,14 +810,14 @@ IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, ListBox&, rBox, void)
                ++nTokenCount;
            }
            sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
            m_pAttachmentED->SetText(sAttach);
            m_xAttachmentED->set_text(sAttach);
        }
    }
}

IMPL_LINK_NOARG(SwMMResultEmailDialog, SendAsHdl_Impl, Button*, void)
IMPL_LINK_NOARG(SwMMResultEmailDialog, SendAsHdl_Impl, weld::Button&, void)
{
    SwMailBodyDialog aDlg(GetFrameWeld());
    SwMailBodyDialog aDlg(m_xDialog.get());
    aDlg.SetBody(m_sBody);
    if (RET_OK == aDlg.run())
    {
@@ -860,7 +826,7 @@ IMPL_LINK_NOARG(SwMMResultEmailDialog, SendAsHdl_Impl, Button*, void)
}

// Send documents as e-mail
IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, void)
{
    SwView* pView = ::GetActiveView();
    std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
@@ -875,7 +841,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
    if (xConfigItem->GetMailServer().isEmpty() ||
            !SwMailMergeHelper::CheckMailAddress(xConfigItem->GetMailAddress()) )
    {
        std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pButton->GetFrameWeld(),
        std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
                                                       VclMessageType::Question, VclButtonsType::YesNo,
                                                       m_sConfigureMail));
        xQueryBox->add_button(Button::GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
@@ -884,7 +850,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
        {
            SwView* pConfigView = pTargetView ? pTargetView : pView;
            SfxAllItemSet aSet(pConfigView->GetPool());
            SwMailConfigDlg aDlg(pButton->GetFrameWeld(), aSet);
            SwMailConfigDlg aDlg(m_xDialog.get(), aSet);
            nRet = aDlg.run();
        }

@@ -894,15 +860,15 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
    //add the documents
    sal_uInt32 nBegin = 0;
    sal_uInt32 nEnd = 0;
    if(m_pSendAllRB->IsChecked())
    if (m_xSendAllRB->get_active())
    {
        nBegin = 0;
        nEnd = xConfigItem->GetMergedDocumentCount();
    }
    else
    {
        nBegin  = static_cast< sal_Int32 >(m_pFromNF->GetValue() - 1);
        nEnd    = static_cast< sal_Int32 >(m_pToNF->GetValue());
        nBegin  = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
        nEnd    = static_cast< sal_Int32 >(m_xToNF->get_value());
        if(nEnd > xConfigItem->GetMergedDocumentCount())
            nEnd = xConfigItem->GetMergedDocumentCount();
    }
@@ -910,7 +876,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
    rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
    SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
    std::shared_ptr<const SfxFilter> pSfxFlt;
    sal_uLong nDocType = reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectedEntryData());
    auto nDocType = m_xSendAsLB->get_active_id().toUInt32();
    OUString sExtension = lcl_GetExtensionForDocType(nDocType);
    switch( nDocType )
    {
@@ -969,28 +935,28 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)

    if(!pSfxFlt)
    {
        endDialog(pButton);
        m_xDialog->response(RET_OK);
        return;
    }
    OUString sMimeType = pSfxFlt->GetMimeType();

    if(m_pSubjectED->GetText().isEmpty())
    if (m_xSubjectED->get_text().isEmpty())
    {
        std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(pButton->GetFrameWeld(), "SubjectDialog",
        std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "SubjectDialog",
                                                         "modules/swriter/ui/subjectdialog.ui"));
        xQuery->SetIsEmptyTextAllowed(true);
        xQuery->SetValue("");
        if(RET_OK == xQuery->run())
        {
            if(!xQuery->GetValue().isEmpty())
                m_pSubjectED->SetText(xQuery->GetValue());
            if (!xQuery->GetValue().isEmpty())
                m_xSubjectED->set_text(xQuery->GetValue());
        }
        else
            return; // back to the dialog
    }
    if(!bAsBody && m_pAttachmentED->GetText().isEmpty())
    if(!bAsBody && m_xAttachmentED->get_text().isEmpty())
    {
        std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(pButton->GetFrameWeld(), "AttachNameDialog",
        std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "AttachNameDialog",
                                                         "modules/swriter/ui/attachnamedialog.ui"));
        xQuery->SetIsEmptyTextAllowed(false);
        if (RET_OK == xQuery->run())
@@ -1003,19 +969,19 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
                ++nTokenCount;
            }
            sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType(
                     reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectedEntryData())));
            m_pAttachmentED->SetText(sAttach);
                                                   m_xSendAsLB->get_active_id().toUInt32()));
            m_xAttachmentED->set_text(sAttach);
        }
        else
            return; // back to the dialog
    }
    OUString sEMailColumn = m_pMailToLB->GetSelectedEntry();
    OUString sEMailColumn = m_xMailToLB->get_active_text();
    OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
    Reference< sdbcx::XColumnsSupplier > xColsSupp( xConfigItem->GetResultSet(), UNO_QUERY);
    Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
    if(sEMailColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
    {
        endDialog(pButton);
        m_xDialog->response(RET_OK);
        return;
    }

@@ -1058,7 +1024,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
    //TODO/CLEANUP
    //predetermined breaking point
    Application::Reschedule( true );
    endDialog(pButton);
    m_xDialog->response(RET_OK);
    for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
    {
        SwDocMergeInfo& rInfo = xConfigItem->GetDocumentMergeInfo(nDoc);
@@ -1145,7 +1111,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
        {
            sBody = m_sBody;
            aDesc.sAttachmentURL = aName.GetValue();
            OUString sAttachment(m_pAttachmentED->GetText());
            OUString sAttachment(m_xAttachmentED->get_text());
            sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
            if (2 > nTokenCount)
            {
@@ -1196,7 +1162,7 @@ IMPL_LINK(SwMMResultEmailDialog, SendDocumentsHdl_Impl, Button*, pButton, void)
        else
            aDesc.sBodyMimeType = "text/plain; charset=UTF-8; format=flowed";

        aDesc.sSubject = m_pSubjectED->GetText();
        aDesc.sSubject = m_xSubjectED->get_text();
        aDesc.sCC = m_sCC;
        aDesc.sBCC = m_sBCC;
        pDlg->AddDocument( aDesc );
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx
index 9633439..371c7e0 100644
--- a/sw/source/ui/dialog/swdlgfact.cxx
+++ b/sw/source/ui/dialog/swdlgfact.cxx
@@ -1218,10 +1218,10 @@ void SwAbstractDialogFactory_Impl::ExecuteMMResultPrintDialog(weld::Window* pPar
    aDialog.run();
}

void SwAbstractDialogFactory_Impl::ExecuteMMResultEmailDialog()
void SwAbstractDialogFactory_Impl::ExecuteMMResultEmailDialog(weld::Window* pParent)
{
    ScopedVclPtrInstance<SwMMResultEmailDialog> pDialog;
    pDialog->Execute();
    SwMMResultEmailDialog aDialog(pParent);
    aDialog.run();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx
index 993d0aa..3943fb1 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -722,7 +722,7 @@ public:

    virtual void ExecuteMMResultSaveDialog(weld::Window* pParent) override;
    virtual void ExecuteMMResultPrintDialog(weld::Window* pParent) override;
    virtual void ExecuteMMResultEmailDialog() override;
    virtual void ExecuteMMResultEmailDialog(weld::Window* pParent) override;
};

#endif
diff --git a/sw/source/ui/inc/mmresultdialogs.hxx b/sw/source/ui/inc/mmresultdialogs.hxx
index 7f7dad5..a26ee9f 100644
--- a/sw/source/ui/inc/mmresultdialogs.hxx
+++ b/sw/source/ui/inc/mmresultdialogs.hxx
@@ -92,51 +92,41 @@ public:
};

/// Dialog implementing the sending as email of the result document.
class SwMMResultEmailDialog : public SfxModalDialog
class SwMMResultEmailDialog : public SfxDialogController
{
    VclPtr<FixedText>      m_pMailToFT;
    VclPtr<ListBox>        m_pMailToLB;
    VclPtr<PushButton>     m_pCopyToPB;

    VclPtr<FixedText>      m_pSubjectFT;
    VclPtr<Edit>           m_pSubjectED;

    VclPtr<FixedText>      m_pSendAsFT;
    VclPtr<ListBox>        m_pSendAsLB;
    VclPtr<PushButton>     m_pSendAsPB;

    VclPtr<VclContainer>   m_pAttachmentGroup;
    VclPtr<Edit>           m_pAttachmentED;

    VclPtr<RadioButton>    m_pSendAllRB;

    VclPtr<RadioButton>    m_pFromRB;
    VclPtr<NumericField>   m_pFromNF;
    VclPtr<FixedText>      m_pToFT;
    VclPtr<NumericField>   m_pToNF;

    VclPtr<Button>         m_pOKButton;

    OUString const  m_sConfigureMail;

    OUString        m_sCC;
    OUString        m_sBCC;

    OUString        m_sBody;

    DECL_LINK(CopyToHdl_Impl, Button*, void);
    DECL_LINK(SendTypeHdl_Impl, ListBox&, void);
    DECL_LINK(SendAsHdl_Impl, Button*, void);
    DECL_LINK(SendDocumentsHdl_Impl, Button*, void);
    DECL_LINK(DocumentSelectionHdl_Impl, Button*, void);
    std::unique_ptr<weld::Label> m_xMailToFT;
    std::unique_ptr<weld::ComboBox> m_xMailToLB;
    std::unique_ptr<weld::Button> m_xCopyToPB;
    std::unique_ptr<weld::Label> m_xSubjectFT;
    std::unique_ptr<weld::Entry> m_xSubjectED;
    std::unique_ptr<weld::Label> m_xSendAsFT;
    std::unique_ptr<weld::ComboBox> m_xSendAsLB;
    std::unique_ptr<weld::Button> m_xSendAsPB;
    std::unique_ptr<weld::Widget> m_xAttachmentGroup;
    std::unique_ptr<weld::Entry> m_xAttachmentED;
    std::unique_ptr<weld::RadioButton> m_xSendAllRB;
    std::unique_ptr<weld::RadioButton> m_xFromRB;
    std::unique_ptr<weld::SpinButton> m_xFromNF;
    std::unique_ptr<weld::Label> m_xToFT;
    std::unique_ptr<weld::SpinButton> m_xToNF;
    std::unique_ptr<weld::Button> m_xOKButton;

    DECL_LINK(CopyToHdl_Impl, weld::Button&, void);
    DECL_LINK(SendTypeHdl_Impl, weld::ComboBox&, void);
    DECL_LINK(SendAsHdl_Impl, weld::Button&, void);
    DECL_LINK(SendDocumentsHdl_Impl, weld::Button&, void);
    DECL_LINK(DocumentSelectionHdl_Impl, weld::ToggleButton&, void);

    void FillInEmailSettings();

public:
    SwMMResultEmailDialog();
    SwMMResultEmailDialog(weld::Window *pParent);
    virtual ~SwMMResultEmailDialog() override;

    virtual void dispose() override;
};

struct SwMailDescriptor
diff --git a/sw/source/uibase/app/apphdl.cxx b/sw/source/uibase/app/apphdl.cxx
index 89a99f7..fb6270a 100644
--- a/sw/source/uibase/app/apphdl.cxx
+++ b/sw/source/uibase/app/apphdl.cxx
@@ -768,7 +768,7 @@ void SwModule::ExecOther(SfxRequest& rReq)
            {
                case FN_MAILMERGE_SAVE_DOCUMENTS: pFact->ExecuteMMResultSaveDialog(rReq.GetFrameWeld()); break;
                case FN_MAILMERGE_PRINT_DOCUMENTS: pFact->ExecuteMMResultPrintDialog(rReq.GetFrameWeld()); break;
                case FN_MAILMERGE_EMAIL_DOCUMENTS: pFact->ExecuteMMResultEmailDialog(); break;
                case FN_MAILMERGE_EMAIL_DOCUMENTS: pFact->ExecuteMMResultEmailDialog(rReq.GetFrameWeld()); break;
            }
        }
        break;
diff --git a/sw/uiconfig/swriter/ui/mmresultemaildialog.ui b/sw/uiconfig/swriter/ui/mmresultemaildialog.ui
index 08f5bfc..5f10bf7 100644
--- a/sw/uiconfig/swriter/ui/mmresultemaildialog.ui
+++ b/sw/uiconfig/swriter/ui/mmresultemaildialog.ui
@@ -1,42 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.22.1 -->
<interface domain="sw">
  <requires lib="gtk+" version="3.18"/>
  <object class="GtkListStore" id="liststore1">
    <columns>
      <!-- column-name gchararray1 -->
      <column type="gchararray"/>
      <!-- column-name gint1 -->
      <column type="gint"/>
    </columns>
    <data>
      <row>
        <col id="0" translatable="yes" context="mmresultemaildialog|liststore1">OpenDocument Text</col>
        <col id="1">1</col>
      </row>
      <row>
        <col id="0" translatable="yes" context="mmresultemaildialog|liststore1">Adobe PDF-Document</col>
        <col id="1">2</col>
      </row>
      <row>
        <col id="0" translatable="yes" context="mmresultemaildialog|liststore1">Microsoft Word Document</col>
        <col id="1">3</col>
      </row>
      <row>
        <col id="0" translatable="yes" context="mmresultemaildialog|liststore1">HTML Message</col>
        <col id="1">4</col>
      </row>
      <row>
        <col id="0" translatable="yes" context="mmresultemaildialog|liststore1">Plain Text</col>
        <col id="1">5</col>
      </row>
    </data>
  <object class="GtkAdjustment" id="adjustment1">
    <property name="upper">16000</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkAdjustment" id="adjustment2">
    <property name="upper">16000</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
  </object>
  <object class="GtkDialog" id="MMResultEmailDialog">
    <property name="can_focus">False</property>
    <property name="border_width">6</property>
    <property name="title" translatable="yes" context="mmresultemaildialog|MMResultEmailDialog">E-Mail merged document</property>
    <property name="modal">True</property>
    <property name="default_width">0</property>
    <property name="default_height">0</property>
    <property name="type_hint">dialog</property>
    <child>
      <placeholder/>
    </child>
    <child internal-child="vbox">
      <object class="GtkBox" id="dialog-vbox1">
        <property name="can_focus">False</property>
@@ -129,10 +115,10 @@
                          <object class="GtkLabel" id="mailtoft">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="xalign">0</property>
                            <property name="label" translatable="yes" context="mmresultemaildialog|mailtoft">T_o</property>
                            <property name="use_underline">True</property>
                            <property name="mnemonic_widget">mailto</property>
                            <property name="xalign">0</property>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>
@@ -167,10 +153,10 @@
                          <object class="GtkLabel" id="subjectft">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="xalign">0</property>
                            <property name="label" translatable="yes" context="mmresultemaildialog|subjectft">S_ubject</property>
                            <property name="use_underline">True</property>
                            <property name="mnemonic_widget">subject</property>
                            <property name="xalign">0</property>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>
@@ -192,10 +178,10 @@
                          <object class="GtkLabel" id="sendasft">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="xalign">0</property>
                            <property name="label" translatable="yes" context="mmresultemaildialog|sendasft">Sen_d as</property>
                            <property name="use_underline">True</property>
                            <property name="mnemonic_widget">sendas</property>
                            <property name="xalign">0</property>
                          </object>
                          <packing>
                            <property name="left_attach">0</property>
@@ -203,11 +189,17 @@
                          </packing>
                        </child>
                        <child>
                          <object class="GtkComboBox" id="sendas">
                          <object class="GtkComboBoxText" id="sendas">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="hexpand">True</property>
                            <property name="model">liststore1</property>
                            <items>
                              <item id="1" translatable="yes" context="mmresultemaildialog|liststore1">OpenDocument Text</item>
                              <item id="2" translatable="yes" context="mmresultemaildialog|liststore1">Adobe PDF-Document</item>
                              <item id="3" translatable="yes" context="mmresultemaildialog|liststore1">Microsoft Word Document</item>
                              <item id="4" translatable="yes" context="mmresultemaildialog|liststore1">HTML Message</item>
                              <item id="5" translatable="yes" context="mmresultemaildialog|liststore1">Plain Text</item>
                            </items>
                          </object>
                          <packing>
                            <property name="left_attach">1</property>
@@ -261,10 +253,10 @@
                          <object class="GtkLabel" id="attachft">
                            <property name="visible">True</property>
                            <property name="can_focus">False</property>
                            <property name="xalign">0</property>
                            <property name="label" translatable="yes" context="mmresultemaildialog|attachft">Name of the a_ttachment</property>
                            <property name="use_underline">True</property>
                            <property name="mnemonic_widget">attach</property>
                            <property name="xalign">0</property>
                          </object>
                        </child>
                      </object>
@@ -321,7 +313,6 @@
                        <property name="xalign">0</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">fromrb</property>
                      </object>
                      <packing>
                        <property name="expand">False</property>
@@ -345,7 +336,7 @@
                            <property name="draw_indicator">True</property>
                            <property name="group">sendallrb</property>
                            <accessibility>
                              <relation type="label-for" target="from-nospin"/>
                              <relation type="label-for" target="from"/>
                            </accessibility>
                          </object>
                          <packing>
@@ -359,7 +350,7 @@
                            <property name="can_focus">False</property>
                            <property name="label" translatable="yes" context="mmresultemaildialog|toft">_To</property>
                            <property name="use_underline">True</property>
                            <property name="mnemonic_widget">to-nospin</property>
                            <property name="mnemonic_widget">to</property>
                          </object>
                          <packing>
                            <property name="left_attach">2</property>
@@ -367,10 +358,11 @@
                          </packing>
                        </child>
                        <child>
                          <object class="GtkSpinButton" id="from-nospin">
                          <object class="GtkSpinButton" id="from">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="text" translatable="no">1</property>
                            <property name="text">1</property>
                            <property name="adjustment">adjustment2</property>
                            <accessibility>
                              <relation type="labelled-by" target="fromrb"/>
                            </accessibility>
@@ -381,10 +373,11 @@
                          </packing>
                        </child>
                        <child>
                          <object class="GtkSpinButton" id="to-nospin">
                          <object class="GtkSpinButton" id="to">
                            <property name="visible">True</property>
                            <property name="can_focus">True</property>
                            <property name="text">1</property>
                            <property name="adjustment">adjustment1</property>
                          </object>
                          <packing>
                            <property name="left_attach">3</property>