vcl/inc/printdlg.hxx           |    7 +
 vcl/source/window/printdlg.cxx |  170 ++++++++++++++++++++---------------------
 2 files changed, 92 insertions(+), 85 deletions(-)

New commits:
commit 2f28a17f01526f748859ad76bf73cb41fdfa7d6d
Author:     Mike Kaganski <[email protected]>
AuthorDate: Fri Nov 14 11:49:40 2025 +0500
Commit:     Mike Kaganski <[email protected]>
CommitDate: Fri Nov 14 15:27:35 2025 +0100

    Split handler function per control
    
    It just feels wrong, that we use a chain of if's to select which
    control was changed, when we already know that.
    
    Change-Id: If7f8c64f59dbdf55c9f8e1f9dc7c6bb2b6c68f76
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194004
    Reviewed-by: Mike Kaganski <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index b2c067c99cc0..8071da7af2dd 100644
--- a/vcl/inc/printdlg.hxx
+++ b/vcl/inc/printdlg.hxx
@@ -203,7 +203,12 @@ namespace vcl
         DECL_LINK(updatePreviewNoCacheIdle, Timer*, void);
 
         DECL_LINK( ClickHdl, weld::Button&, void );
-        DECL_LINK( SelectHdl, weld::ComboBox&, void );
+        DECL_LINK(SelectPrinterHdl, weld::ComboBox&, void);
+        DECL_LINK(SelectPaperSidesHdl, weld::ComboBox&, void);
+        DECL_LINK(SelectOrientationHdl, weld::ComboBox&, void);
+        DECL_LINK(SelectNupOrderHdl, weld::ComboBox&, void);
+        DECL_LINK(SelectNupPagesHdl, weld::ComboBox&, void);
+        DECL_LINK(SelectPaperSizeHdl, weld::ComboBox&, void);
         DECL_LINK( ActivateHdl, weld::Entry&, bool );
         DECL_LINK( FocusOutHdl, weld::Widget&, void );
         DECL_LINK( SpinModifyHdl, weld::SpinButton&, void );
diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx
index 1988cc626c33..c969e0939c35 100644
--- a/vcl/source/window/printdlg.cxx
+++ b/vcl/source/window/printdlg.cxx
@@ -679,12 +679,12 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, 
std::shared_ptr<PrinterControl
     mxBorderCB->connect_toggled( LINK( this, PrintDialog, ToggleHdl ) );
 
     // setup select hdl
-    mxPrinters->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
-    mxPaperSidesBox->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
-    mxNupPagesBox->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
-    mxOrientationBox->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
-    mxNupOrderBox->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
-    mxPaperSizeBox->connect_changed( LINK( this, PrintDialog, SelectHdl ) );
+    mxPrinters->connect_changed(LINK(this, PrintDialog, SelectPrinterHdl));
+    mxPaperSidesBox->connect_changed(LINK(this, PrintDialog, 
SelectPaperSidesHdl));
+    mxNupPagesBox->connect_changed(LINK(this, PrintDialog, SelectNupPagesHdl));
+    mxOrientationBox->connect_changed(LINK(this, PrintDialog, 
SelectOrientationHdl));
+    mxNupOrderBox->connect_changed(LINK(this, PrintDialog, SelectNupOrderHdl));
+    mxPaperSizeBox->connect_changed(LINK(this, PrintDialog, 
SelectPaperSizeHdl));
 
     // setup modify hdl
     mxPageEdit->connect_activate( LINK( this, PrintDialog, ActivateHdl ) );
@@ -1965,97 +1965,99 @@ IMPL_LINK(PrintDialog, ClickHdl, weld::Button&, 
rButton, void)
 
 }
 
-IMPL_LINK( PrintDialog, SelectHdl, weld::ComboBox&, rBox, void )
+IMPL_LINK_NOARG( PrintDialog, SelectPrinterHdl, weld::ComboBox&, void )
 {
-    if (&rBox == mxPrinters.get())
+    if (!isPrintToFile())
     {
-        if ( !isPrintToFile() )
-        {
-            OUString aNewPrinter(rBox.get_active_text());
-            // set new printer
-            maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) 
);
-            maPController->resetPrinterOptions( false  );
-            // invalidate page cache and start fresh
-            maPController->invalidatePageCache();
-            maFirstPageSize = Size();
-
-            updateOrientationBox();
-            updatePageSize(mxOrientationBox->get_active());
-
-            // update text fields
-            mxOKButton->set_label(maPrintText);
-            updatePrinterText();
-            updateNup(false);
-            setPaperSizes();
-            maUpdatePreviewIdle.Start();
-        }
-        else // print to file
-        {
-            // use the default printer or FIXME: the last used one?
-            maPController->setPrinter( VclPtrInstance<Printer>( 
Printer::GetDefaultPrinterName() ) );
-            mxOKButton->set_label(maPrintToFileText);
-            maPController->resetPrinterOptions( true );
-
-            setPaperSizes();
-            updateOrientationBox();
-            updatePageSize(mxOrientationBox->get_active());
-            maUpdatePreviewIdle.Start();
-        }
+        OUString aNewPrinter(mxPrinters->get_active_text());
+        // set new printer
+        maPController->setPrinter(VclPtrInstance<Printer>(aNewPrinter));
+        maPController->resetPrinterOptions(false);
+        // invalidate page cache and start fresh
+        maPController->invalidatePageCache();
+        maFirstPageSize = Size();
 
-        setupPaperSidesBox();
+        updateOrientationBox();
+        updatePageSize(mxOrientationBox->get_active());
 
-        // Related: tdf#159995 changing a listbox's active item does not
-        // trigger an update to the preview so force an update to the
-        // preview by calling each active listbox's select handler after
-        // changing the active printer.
-        if ( mxOrientationBox->get_sensitive() )
-            SelectHdl(*mxOrientationBox);
-        if ( mxPaperSizeBox->get_sensitive() )
-            SelectHdl(*mxPaperSizeBox);
-    }
-    else if ( &rBox == mxPaperSidesBox.get() )
-    {
-        DuplexMode eDuplex = 
static_cast<DuplexMode>(mxPaperSidesBox->get_active() + 1);
-        maPController->getPrinter()->SetDuplexMode( eDuplex );
+        // update text fields
+        mxOKButton->set_label(maPrintText);
+        updatePrinterText();
+        updateNup(false);
+        setPaperSizes();
+        maUpdatePreviewIdle.Start();
     }
-    else if( &rBox == mxOrientationBox.get() )
+    else // print to file
     {
-        int nOrientation = mxOrientationBox->get_active();
-        if ( nOrientation != ORIENTATION_AUTOMATIC )
-            setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ), 
true );
+        // use the default printer or FIXME: the last used one?
+        
maPController->setPrinter(VclPtrInstance<Printer>(Printer::GetDefaultPrinterName()));
+        mxOKButton->set_label(maPrintToFileText);
+        maPController->resetPrinterOptions(true);
 
-        updatePageSize(nOrientation);
-        updateNup( false );
-    }
-    else if ( &rBox == mxNupOrderBox.get() )
-    {
-        updateNup();
-    }
-    else if( &rBox == mxNupPagesBox.get() )
-    {
-        if( !mxPagesBtn->get_active() )
-            mxPagesBtn->set_active(true);
+        setPaperSizes();
+        updateOrientationBox();
         updatePageSize(mxOrientationBox->get_active());
-        updateNupFromPages( false );
+        maUpdatePreviewIdle.Start();
     }
-    else if ( &rBox == mxPaperSizeBox.get() )
-    {
-        VclPtr<Printer> aPrt( maPController->getPrinter() );
-        PaperInfo aInfo = aPrt->GetPaperInfo( rBox.get_active() );
-        aInfo.doSloppyFit(true);
-        mePaper = aInfo.getPaper();
 
-        if ( mePaper == PAPER_USER )
-            aPrt->SetPaperSizeUser( Size( aInfo.getWidth(), aInfo.getHeight() 
) );
-        else
-            aPrt->SetPaper( mePaper );
+    setupPaperSidesBox();
 
-        maPController->setPaperSizeFromUser( Size( aInfo.getWidth(), 
aInfo.getHeight() ) );
+    // Related: tdf#159995 changing a listbox's active item does not
+    // trigger an update to the preview so force an update to the
+    // preview by calling each active listbox's select handler after
+    // changing the active printer.
+    if (mxOrientationBox->get_sensitive())
+        SelectOrientationHdl(*mxOrientationBox);
+    if (mxPaperSizeBox->get_sensitive())
+        SelectPaperSizeHdl(*mxPaperSizeBox);
+}
 
-        updatePageSize(mxOrientationBox->get_active());
+IMPL_LINK_NOARG(PrintDialog, SelectPaperSidesHdl, weld::ComboBox&, void)
+{
+    DuplexMode eDuplex = static_cast<DuplexMode>(mxPaperSidesBox->get_active() 
+ 1);
+    maPController->getPrinter()->SetDuplexMode(eDuplex);
+}
 
-        maUpdatePreviewNoCacheIdle.Start();
-    }
+IMPL_LINK_NOARG(PrintDialog, SelectOrientationHdl, weld::ComboBox&, void)
+{
+    int nOrientation = mxOrientationBox->get_active();
+    if (nOrientation != ORIENTATION_AUTOMATIC)
+        setPaperOrientation(static_cast<Orientation>(nOrientation - 1), true);
+
+    updatePageSize(nOrientation);
+    updateNup(false);
+}
+
+IMPL_LINK_NOARG(PrintDialog, SelectNupOrderHdl, weld::ComboBox&, void)
+{
+    updateNup();
+}
+
+IMPL_LINK_NOARG(PrintDialog, SelectNupPagesHdl, weld::ComboBox&, void)
+{
+    if (!mxPagesBtn->get_active())
+        mxPagesBtn->set_active(true);
+    updatePageSize(mxOrientationBox->get_active());
+    updateNupFromPages(false);
+}
+
+IMPL_LINK_NOARG(PrintDialog, SelectPaperSizeHdl, weld::ComboBox&, void)
+{
+    VclPtr<Printer> aPrt(maPController->getPrinter());
+    PaperInfo aInfo = aPrt->GetPaperInfo(mxPaperSizeBox->get_active());
+    aInfo.doSloppyFit(true);
+    mePaper = aInfo.getPaper();
+
+    if (mePaper == PAPER_USER)
+        aPrt->SetPaperSizeUser(Size(aInfo.getWidth(), aInfo.getHeight()));
+    else
+        aPrt->SetPaper(mePaper);
+
+    maPController->setPaperSizeFromUser(Size(aInfo.getWidth(), 
aInfo.getHeight()));
+
+    updatePageSize(mxOrientationBox->get_active());
+
+    maUpdatePreviewNoCacheIdle.Start();
 }
 
 IMPL_LINK_NOARG(PrintDialog, MetricSpinModifyHdl, weld::MetricSpinButton&, 
void)

Reply via email to