tdf#126744 Transfer paper size and orientation to new printer

when selected from the Printer dropdown list

Change-Id: Iedd53575c2e9146b663cf21b42b495473abe5165
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88373
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <bubli@bubli.org>
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index 7c3a1ec..dc8409e 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -788,6 +788,20 @@ weld::Window* PrinterController::getWindow() const

void PrinterController::setPrinter( const VclPtr<Printer>& i_rPrinter )
{
    VclPtr<Printer> xPrinter = mpImplData->mxPrinter;

    Size aPaperSize;          // Save current paper size
    Orientation eOrientation = Orientation::Portrait; // Save current paper orientation
    bool bSavedSizeOrientation = false;

    // #tdf 126744 Transfer paper size and orientation settings to newly selected printer
    if ( xPrinter.get() )
    {
        aPaperSize = xPrinter->GetPaperSize();
        eOrientation = xPrinter->GetOrientation();
        bSavedSizeOrientation = true;
    }

    mpImplData->mxPrinter = i_rPrinter;
    setValue( "Name",
              css::uno::makeAny( i_rPrinter->GetName() ) );
@@ -795,6 +809,13 @@ void PrinterController::setPrinter( const VclPtr<Printer>& i_rPrinter )
    mpImplData->mxPrinter->Push();
    mpImplData->mxPrinter->SetMapMode(MapMode(MapUnit::Map100thMM));
    mpImplData->maDefaultPageSize = mpImplData->mxPrinter->GetPaperSize();

    if ( bSavedSizeOrientation )
    {
          mpImplData->mxPrinter->SetPaperSizeUser(aPaperSize, !mpImplData->isFixedPageSize());
          mpImplData->mxPrinter->SetOrientation(eOrientation);
    }

    mpImplData->mbPapersizeFromUser = false;
    mpImplData->mxPrinter->Pop();
    mpImplData->mnFixedPaperBin = -1;
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 1f88e9d..0564ffa 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -1918,7 +1918,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
            mxOKButton->set_label(maPrintText);
            updatePrinterText();
            setPaperSizes();
            preparePreview(false);
            preparePreview(true);
        }
        else // print to file
        {
@@ -1973,7 +1973,7 @@ IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
        checkPaperSize( aPaperSize );
        maPController->setPaperSizeFromUser( aPaperSize );

        preparePreview(false);
        preparePreview(true);
    }
}