[Libreoffice-commits] core.git: sfx2/source

Samuel Mehrbrodt (via logerrit) logerrit at kemper.freedesktop.org
Thu Nov 26 08:33:34 UTC 2020


 sfx2/source/view/viewprn.cxx |  130 +++++++++++++++++++++++--------------------
 1 file changed, 70 insertions(+), 60 deletions(-)

New commits:
commit 75ec00583e03c3c09a64836da43f9f48d4fb3990
Author:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
AuthorDate: Thu Nov 26 08:32:50 2020 +0100
Commit:     Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
CommitDate: Thu Nov 26 09:32:45 2020 +0100

    Separate uno:Printer and uno:PrinterSetup handling
    
    Change-Id: I669bea397c5b9f4afa665a97f50182f3357340df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106654
    Tested-by: Jenkins
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 796a505ed8d4..a01be90a0395 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -757,8 +757,31 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
             break;
         }
 
-        case SID_SETUPPRINTER : // display the printer settings dialogue : File > Printer Settings...
-        case SID_PRINTER_NAME : // only for recorded macros
+        case SID_PRINTER_NAME: // for recorded macros
+        {
+            // get printer and printer settings from the document
+            SfxPrinter* pDocPrinter = GetPrinter(true);
+            const SfxStringItem* pPrinterItem = rReq.GetArg<SfxStringItem>(SID_PRINTER_NAME);
+            if (!pPrinterItem)
+            {
+                rReq.Ignore();
+                break;
+            }
+            // use PrinterName parameter to create a printer
+            pPrinter = VclPtr<SfxPrinter>::Create(pDocPrinter->GetOptions().Clone(),
+                                                  pPrinterItem->GetValue());
+
+            if (!pPrinter->IsKnown())
+            {
+                pPrinter.disposeAndClear();
+                rReq.Ignore();
+                break;
+            }
+            SetPrinter(pPrinter, SfxPrinterChangeFlags::PRINTER);
+            rReq.Done();
+            break;
+        }
+        case SID_SETUPPRINTER : // display the printer settings dialog : File > Printer Settings...
         {
             // get printer and printer settings from the document
             SfxPrinter *pDocPrinter = GetPrinter(true);
@@ -775,14 +798,6 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                     pPrinter.disposeAndClear();
             }
 
-            if ( SID_PRINTER_NAME == nId )
-            {
-                // just set a recorded printer name
-                if ( pPrinter )
-                    SetPrinter( pPrinter, SfxPrinterChangeFlags::PRINTER  );
-                return;
-            }
-
             // no PrinterName parameter in ItemSet or the PrinterName points to an unknown printer
             if ( !pPrinter )
                 // use default printer from document
@@ -820,68 +835,63 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
                 return;
             }
 
-            // Open Printer Setup dialog
-            if ( nId == SID_SETUPPRINTER )
+            // Open Printer Setup dialog (needs a temporary printer)
+            VclPtr<SfxPrinter> pDlgPrinter = pPrinter->Clone();
+            PrinterSetupDialog aPrintSetupDlg(GetFrameWeld());
+            std::unique_ptr<SfxDialogExecutor_Impl> pExecutor;
+
+            if (pImpl->m_bHasPrintOptions && HasPrintOptionsPage())
             {
-                // PrinterDialog needs a temporary printer
-                VclPtr<SfxPrinter> pDlgPrinter = pPrinter->Clone();
+                // additional controls for dialog
+                pExecutor.reset(new SfxDialogExecutor_Impl(this, aPrintSetupDlg));
+                if (bPrintOnHelp)
+                    pExecutor->DisableHelp();
+                aPrintSetupDlg.SetOptionsHdl(pExecutor->GetLink());
+            }
 
-                // execute PrinterSetupDialog
-                PrinterSetupDialog aPrintSetupDlg(GetFrameWeld());
-                std::unique_ptr<SfxDialogExecutor_Impl> pExecutor;
+            aPrintSetupDlg.SetPrinter(pDlgPrinter);
+            nDialogRet = aPrintSetupDlg.run();
 
-                if (pImpl->m_bHasPrintOptions && HasPrintOptionsPage())
+            if (pExecutor && pExecutor->GetOptions())
+            {
+                if (nDialogRet == RET_OK)
+                    // remark: have to be recorded if possible!
+                    pDlgPrinter->SetOptions(*pExecutor->GetOptions());
+                else
                 {
-                    // additional controls for dialog
-                    pExecutor.reset( new SfxDialogExecutor_Impl( this, aPrintSetupDlg ) );
-                    if ( bPrintOnHelp )
-                        pExecutor->DisableHelp();
-                    aPrintSetupDlg.SetOptionsHdl( pExecutor->GetLink() );
+                    pPrinter->SetOptions(*pExecutor->GetOptions());
+                    SetPrinter(pPrinter, SfxPrinterChangeFlags::OPTIONS);
                 }
+            }
 
-                aPrintSetupDlg.SetPrinter( pDlgPrinter );
-                nDialogRet = aPrintSetupDlg.run();
+            // no recording of PrinterSetup except printer name (is printer dependent)
+            rReq.Ignore();
 
-                if ( pExecutor && pExecutor->GetOptions() )
+            if (nDialogRet == RET_OK)
+            {
+                if (pPrinter->GetName() != pDlgPrinter->GetName())
                 {
-                    if ( nDialogRet == RET_OK )
-                        // remark: have to be recorded if possible!
-                        pDlgPrinter->SetOptions( *pExecutor->GetOptions() );
-                    else
-                    {
-                        pPrinter->SetOptions( *pExecutor->GetOptions() );
-                        SetPrinter( pPrinter, SfxPrinterChangeFlags::OPTIONS );
-                    }
+                    // user has changed the printer -> macro recording
+                    SfxRequest aReq(GetViewFrame(), SID_PRINTER_NAME);
+                    aReq.AppendItem(SfxStringItem(SID_PRINTER_NAME, pDlgPrinter->GetName()));
+                    aReq.Done();
                 }
 
-                // no recording of PrinterSetup except printer name (is printer dependent)
-                rReq.Ignore();
-
-                if ( nDialogRet == RET_OK )
-                {
-                    if ( pPrinter->GetName() != pDlgPrinter->GetName() )
-                    {
-                        // user has changed the printer -> macro recording
-                        SfxRequest aReq( GetViewFrame(), SID_PRINTER_NAME );
-                        aReq.AppendItem( SfxStringItem( SID_PRINTER_NAME, pDlgPrinter->GetName() ) );
-                        aReq.Done();
-                    }
+                // take the changes made in the dialog
+                SetPrinter_Impl(pDlgPrinter);
 
-                    // take the changes made in the dialog
-                    SetPrinter_Impl( pDlgPrinter );
-
-                    // forget new printer, it was taken over (as pPrinter) or deleted
-                    pDlgPrinter = nullptr;
-                    mbPrinterSettingsModified = true;
-                }
-                else
-                {
-                    // PrinterDialog is used to transfer information on printing,
-                    // so it will only be deleted here if dialog was cancelled
-                    pDlgPrinter.disposeAndClear();
-                    rReq.Ignore();
-                }
+                // forget new printer, it was taken over (as pPrinter) or deleted
+                pDlgPrinter = nullptr;
+                mbPrinterSettingsModified = true;
             }
+            else
+            {
+                // PrinterDialog is used to transfer information on printing,
+                // so it will only be deleted here if dialog was cancelled
+                pDlgPrinter.disposeAndClear();
+                rReq.Ignore();
+            }
+            break;
         }
     }
 }


More information about the Libreoffice-commits mailing list