tdf#142589 Impress UI: fix Start button of Custom Slide Shows

This button started the selected custom slide show only
by changing the (already) selected custom slide show, and
enabling the checkbox "Use custom slide show". Otherwise it
started always the full show.

Remove the redundant checkbox "Use custom slide show" of the
dialog window "Custom Slide Shows" (Slide Show->Custom Slide Show...)
to avoid inconsistent behavior of the Start button (which could
start the full show instead of the selected custom slide show).

Now Start button of the dialog starts the selected custom slide
show only once, i.e. it doesn't modify the global slide show
settings for all the next slide shows (that is already handled
by Slide Show->Slide Show Settings->Range->"Custom slide show:"
and Slide Show->Slide Show Settings->Range->"All slides").

Change-Id: I6e97a69c546870199d5a45d9a6ad102e30d820c2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117876
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index 7d4c3c9..80a7995 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -108,6 +108,7 @@ namespace sd
        bool mbAnimationAllowed;
        sal_Int32 mnPauseTimeout;
        bool mbShowPauseLogo;
        bool mbStartCustomShow;

        PresentationSettings();
    };
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index 8fa1622..444677f 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -49,6 +49,7 @@
#include <sdpage.hxx>
#include <unomodel.hxx>
#include <osl/thread.hxx>
#include <slideshow.hxx>

using namespace ::com::sun::star;

@@ -717,6 +718,22 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testSearchAllInDocumentAndNotes)
    Scheduler::ProcessEventsToIdle();
}

CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf142589)
{
    mxComponent = loadFromDesktop("private:factory/simpress",
                                  "com.sun.star.presentation.PresentationDocument");
    CPPUNIT_ASSERT(mxComponent.is());

    auto pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
    sd::ViewShell* pViewShell = pImpressDocument->GetDocShell()->GetViewShell();

    SfxRequest aRequest(pViewShell->GetViewFrame(), SID_PRESENTATION);
    pImpressDocument->GetDoc()->getPresentationSettings().mbCustomShow = true;
    pImpressDocument->GetDoc()->getPresentationSettings().mbStartCustomShow = true;
    sd::slideshowhelp::ShowSlideShow(aRequest, *pImpressDocument->GetDoc());
    CPPUNIT_ASSERT_EQUAL(false, pImpressDocument->GetDoc()->getPresentationSettings().mbCustomShow);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 4e7c6c5..baf1d57 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -109,7 +109,8 @@ PresentationSettings::PresentationSettings()
    mbFullScreen( true ),
    mbAnimationAllowed( true ),
    mnPauseTimeout( 0 ),
    mbShowPauseLogo( false )
    mbShowPauseLogo( false ),
    mbStartCustomShow( false )
{
}

diff --git a/sd/source/ui/dlg/custsdlg.cxx b/sd/source/ui/dlg/custsdlg.cxx
index afa9e0b..db2414a 100644
--- a/sd/source/ui/dlg/custsdlg.cxx
+++ b/sd/source/ui/dlg/custsdlg.cxx
@@ -38,7 +38,6 @@ SdCustomShowDlg::SdCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc
    , pCustomShowList(nullptr)
    , bModified(false)
    , m_xLbCustomShows(m_xBuilder->weld_tree_view("customshowlist"))
    , m_xCbxUseCustomShow(m_xBuilder->weld_check_button("usecustomshows"))
    , m_xBtnNew(m_xBuilder->weld_button("new"))
    , m_xBtnEdit(m_xBuilder->weld_button("edit"))
    , m_xBtnRemove(m_xBuilder->weld_button("delete"))
@@ -55,7 +54,6 @@ SdCustomShowDlg::SdCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc
    m_xBtnEdit->connect_clicked( aLink );
    m_xBtnRemove->connect_clicked( aLink );
    m_xBtnCopy->connect_clicked( aLink );
    m_xCbxUseCustomShow->connect_toggled(LINK(this, SdCustomShowDlg, ToggleButtonHdl));
    m_xLbCustomShows->connect_changed( LINK( this, SdCustomShowDlg, SelectListBoxHdl ) );

    m_xBtnStartShow->connect_clicked( LINK( this, SdCustomShowDlg, StartShowHdl ) ); // for test
@@ -76,8 +74,6 @@ SdCustomShowDlg::SdCustomShowDlg(weld::Window* pWindow, SdDrawDocument& rDrawDoc
        pCustomShowList->Seek( nPosToSelect );
    }

    m_xCbxUseCustomShow->set_active(pCustomShowList && rDoc.getPresentationSettings().mbCustomShow);

    CheckState();
}

@@ -93,18 +89,12 @@ void SdCustomShowDlg::CheckState()
    m_xBtnEdit->set_sensitive( bEnable );
    m_xBtnRemove->set_sensitive( bEnable );
    m_xBtnCopy->set_sensitive( bEnable );
    m_xCbxUseCustomShow->set_sensitive( bEnable );
    m_xBtnStartShow->set_sensitive(true);
    m_xBtnStartShow->set_sensitive(bEnable);

    if (bEnable && pCustomShowList)
        pCustomShowList->Seek( nPos );
}

IMPL_LINK( SdCustomShowDlg, ToggleButtonHdl, weld::Toggleable&, r, void )
{
    SelectHdl(&r);
}

IMPL_LINK( SdCustomShowDlg, ClickButtonHdl, weld::Button&, r, void )
{
    SelectHdl(&r);
@@ -241,10 +231,6 @@ void SdCustomShowDlg::SelectHdl(void const *p)

        bModified = true;
    }
    else if( p == m_xCbxUseCustomShow.get() )
    {
        bModified = true;
    }

    CheckState();
}
@@ -258,7 +244,10 @@ IMPL_LINK_NOARG(SdCustomShowDlg, StartShowHdl, weld::Button&, void)
// CheckState
bool SdCustomShowDlg::IsCustomShow() const
{
    return (m_xCbxUseCustomShow->get_sensitive() && m_xCbxUseCustomShow->get_active());
    if (!pCustomShowList->empty())
        return true;
    else
        return false;
}

// SdDefineCustomShowDlg
diff --git a/sd/source/ui/func/fucushow.cxx b/sd/source/ui/func/fucushow.cxx
index a87076b..8c63d02 100644
--- a/sd/source/ui/func/fucushow.cxx
+++ b/sd/source/ui/func/fucushow.cxx
@@ -55,21 +55,32 @@ void FuCustomShowDlg::DoExecute( SfxRequest& )
    vcl::Window* pWin = mpViewShell->GetActiveWindow();
    ScopedVclPtr<AbstractSdCustomShowDlg> pDlg( pFact->CreateSdCustomShowDlg(pWin ? pWin->GetFrameWeld() : nullptr, *mpDoc) );
    sal_uInt16 nRet = pDlg->Execute();
    if( pDlg->IsModified() )
    {
        mpDoc->SetChanged();
        sd::PresentationSettings& rSettings = mpDoc->getPresentationSettings();
        rSettings.mbCustomShow = pDlg->IsCustomShow();
    }
    pDlg.disposeAndClear();
    mpDoc->SetChanged();
    sd::PresentationSettings& rSettings = mpDoc->getPresentationSettings();

    if( nRet == RET_YES )
    {
        // If the custom show is not set by default
        if (!rSettings.mbCustomShow)
        {
            rSettings.mbStartCustomShow = true;
            rSettings.mbCustomShow = pDlg->IsCustomShow();
        }

        mpViewShell->SetStartShowWithDialog(true);

        mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION,
                SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
    }
    if (nRet == RET_OK)
    {
        if (!pDlg->IsCustomShow())
        {
            rSettings.mbCustomShow = false;
            rSettings.mbAll = true;
        }
    }
    pDlg.disposeAndClear();
}

} // end of namespace
diff --git a/sd/source/ui/func/fusldlg.cxx b/sd/source/ui/func/fusldlg.cxx
index 484aa5f..4fcc5fd 100644
--- a/sd/source/ui/func/fusldlg.cxx
+++ b/sd/source/ui/func/fusldlg.cxx
@@ -141,6 +141,7 @@ void FuSlideShowDlg::DoExecute( SfxRequest& )
    {
        bValuesChanged = true;
        rPresentationSettings.mbCustomShow = bValue;
        rPresentationSettings.mbStartCustomShow = false;
    }

    bValue = ITEMVALUE( aDlgSet, ATTR_PRESENT_ENDLESS, SfxBoolItem );
diff --git a/sd/source/ui/inc/custsdlg.hxx b/sd/source/ui/inc/custsdlg.hxx
index 3ef3cfb..cd25983 100644
--- a/sd/source/ui/inc/custsdlg.hxx
+++ b/sd/source/ui/inc/custsdlg.hxx
@@ -33,7 +33,6 @@ private:
    bool            bModified;

    std::unique_ptr<weld::TreeView> m_xLbCustomShows;
    std::unique_ptr<weld::CheckButton> m_xCbxUseCustomShow;
    std::unique_ptr<weld::Button> m_xBtnNew;
    std::unique_ptr<weld::Button> m_xBtnEdit;
    std::unique_ptr<weld::Button> m_xBtnRemove;
@@ -45,7 +44,6 @@ private:
    void            CheckState();

    DECL_LINK( ClickButtonHdl, weld::Button&, void );
    DECL_LINK( ToggleButtonHdl, weld::Toggleable&, void );
    DECL_LINK( SelectListBoxHdl, weld::TreeView&, void );
    DECL_LINK( StartShowHdl, weld::Button&, void );
    void SelectHdl(void const *);
diff --git a/sd/source/ui/inc/slideshow.hxx b/sd/source/ui/inc/slideshow.hxx
index a1eef46..68fe771 100644
--- a/sd/source/ui/inc/slideshow.hxx
+++ b/sd/source/ui/inc/slideshow.hxx
@@ -32,6 +32,7 @@
#include <editeng/unoipset.hxx>

#include <memory>
#include <sddllapi.h>

namespace com::sun::star {
    namespace drawing {
@@ -208,7 +209,7 @@ private:

namespace slideshowhelp
{
    void ShowSlideShow(SfxRequest const & rReq, SdDrawDocument &rDoc);
    SD_DLLPUBLIC void ShowSlideShow(SfxRequest const& rReq, SdDrawDocument& rDoc);
}

}
diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx
index 9fb6986..5e5a3ff 100644
--- a/sd/source/ui/view/drviewse.cxx
+++ b/sd/source/ui/view/drviewse.cxx
@@ -1653,6 +1653,10 @@ namespace slideshowhelp
            //use it whether or not we've been asked to
            //start from the current or first slide
            xPresentation->start();

            // if the custom show not set by default, only show it.
            if (rDoc.getPresentationSettings().mbStartCustomShow)
                rDoc.getPresentationSettings().mbCustomShow = false;
        }
        else if (SID_PRESENTATION_CURRENT_SLIDE == rReq.GetSlot())
        {
diff --git a/sd/uiconfig/simpress/ui/customslideshows.ui b/sd/uiconfig/simpress/ui/customslideshows.ui
index 5e0ac35..f2ca426 100644
--- a/sd/uiconfig/simpress/ui/customslideshows.ui
+++ b/sd/uiconfig/simpress/ui/customslideshows.ui
@@ -146,26 +146,6 @@
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <object class="GtkCheckButton" id="usecustomshows">
                    <property name="label" translatable="yes" context="customslideshows|usecustomshows">_Use custom slide show</property>
                    <property name="visible">True</property>
                    <property name="can_focus">True</property>
                    <property name="receives_default">False</property>
                    <property name="use_underline">True</property>
                    <property name="draw_indicator">True</property>
                    <child internal-child="accessible">
                      <object class="AtkObject" id="usecustomshows-atkobject">
                        <property name="AtkObject::accessible-description" translatable="yes" context="customslideshows|extended_tip|usecustomshows">Runs the custom slide show you selected when you click Start. Otherwise, the entire presentation is shown.</property>
                      </object>
                    </child>
                  </object>
                  <packing>
                    <property name="expand">False</property>
                    <property name="fill">True</property>
                    <property name="position">1</property>
                  </packing>
                </child>
              </object>
              <packing>
                <property name="expand">True</property>