tdf#91362: Don't override printer page autodetection

if printer settings haven't been modified

Change-Id: I68b0096ce6fa0f9e50db640a0acb3039ff7e66b5
Reviewed-on: https://gerrit.libreoffice.org/16454
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index b2d31dd..e3eba8e 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -310,6 +310,7 @@ public:
    const OUString&             GetName() const             { return maPrinterName; }
    const OUString&             GetDriverName() const       { return maDriver; }
    bool                        IsDefPrinter() const        { return mbDefPrinter; }
    void                        SetDefPrinter(bool bDef)    {  mbDefPrinter = bDef; }
    bool                        IsDisplayPrinter() const    { return mpDisplayDev != nullptr; }
    bool                        IsValid() const             { return !IsDisplayPrinter(); }

diff --git a/vcl/generic/print/prtsetup.cxx b/vcl/generic/print/prtsetup.cxx
index e024f08..b3d0766 100644
--- a/vcl/generic/print/prtsetup.cxx
+++ b/vcl/generic/print/prtsetup.cxx
@@ -281,6 +281,7 @@ IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox )
    }
    if( pKey )
    {
        m_pParent->SetDataModified( true );
        PPDValue* pValue = static_cast<PPDValue*>(pBox->GetSelectEntryData());
        m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
        update();
@@ -461,6 +462,7 @@ IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
            FillValueBox( pKey );
        }
    }
    m_pParent->SetDataModified( true );
    return 0;
}

@@ -504,10 +506,12 @@ int SetupPrinterDriver(::psp::PrinterInfo& rJobData)
    int nRet = 0;
    ScopedVclPtrInstance< RTSDialog > aDialog(  rJobData, nullptr  );

    // return 0 if cancel was pressed or if the data
    // weren't modified, 1 otherwise
    if( aDialog->Execute() )
    {
        rJobData = aDialog->getSetup();
        nRet = 1;
        nRet = aDialog->GetDataModified() ? 1 : 0;
    }

    return nRet;
diff --git a/vcl/generic/print/prtsetup.hxx b/vcl/generic/print/prtsetup.hxx
index 240d78e1..766237e 100644
--- a/vcl/generic/print/prtsetup.hxx
+++ b/vcl/generic/print/prtsetup.hxx
@@ -56,6 +56,8 @@ class RTSDialog : public TabDialog
    // some resources
    OUString                m_aInvalidString;

    bool mbDataModified;

    DECL_LINK( ActivatePage, TabControl* );
    DECL_LINK( ClickButton, Button* );

@@ -67,6 +69,9 @@ public:
    virtual void dispose() SAL_OVERRIDE;

    const ::psp::PrinterInfo& getSetup() const { return m_aJobData; }

    void SetDataModified( bool bModified ) { mbDataModified = bModified; }
    bool GetDataModified() const { return mbDataModified; }
};

class RTSPaperPage : public TabPage
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index afec12c..edbae14 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -815,7 +815,12 @@ bool PrinterController::setupPrinter( vcl::Window* i_pParent )

        // reset paper size back to last configured size, not
        // whatever happens to be the current page
        resetPaperToLastConfigured();
        // (but only if the printer config has changed, otherwise
        // don't override printer page auto-detection - tdf#91362)
        if (!mpImplData->mxPrinter->IsDefPrinter())
        {
            resetPaperToLastConfigured();
        }

        // call driver setup
        bRet = mpImplData->mxPrinter->Setup( i_pParent );
@@ -844,6 +849,8 @@ bool PrinterController::setupPrinter( vcl::Window* i_pParent )
            {
                mpImplData->maPageCache.invalidate();
            }
            // Settings have been modified (i.e. this printer is no longer default )
            mpImplData->mxPrinter->SetDefPrinter( false );
        }
        else
        {