sw/source/core/layout/layact.cxx |   12 ++++++++++
 vcl/osx/salinst.cxx              |   44 ++++++++++++++++++++++++++++++++++++---
 vcl/source/gdi/print3.cxx        |   10 ++++++++
 3 files changed, 63 insertions(+), 3 deletions(-)

New commits:
commit 229b0ce8d8453960c213da59770b8bb7b6dca895
Author:     Patrick Luby <plub...@neooffice.org>
AuthorDate: Wed Dec 7 11:40:18 2022 -0500
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Dec 13 06:08:54 2022 +0000

    tdf#151700 Display native print panel even if there are no printers
    
    Prevent the non-native LibreOffice PrintDialog from displaying by creating 
a fake printer if there are no printers. This will allow the LibreOffice 
printing code to proceed with native NSPrintOperation which will display the 
native print panel.
    
    Change-Id: Iee13305520360b0165464889f0ee51b1207dd5ce
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143794
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 22a024bc265d..e8a4a94efc08 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -60,6 +60,7 @@
 #include <osx/runinmain.hxx>
 
 #include <print.h>
+#include <strings.hrc>
 
 #include <comphelper/processfactory.hxx>
 
@@ -125,6 +126,20 @@ public:
 
 }
 
+static OUString& getFallbackPrinterName()
+{
+    static OUString aFallbackPrinter;
+
+    if ( aFallbackPrinter.isEmpty() )
+    {
+        aFallbackPrinter = VclResId( SV_PRINT_DEFPRT_TXT );
+        if ( aFallbackPrinter.isEmpty() )
+            aFallbackPrinter = "Printer";
+    }
+
+    return aFallbackPrinter;
+}
+
 void AquaSalInstance::delayedSettingsChanged( bool bInvalidate )
 {
     osl::Guard< comphelper::SolarMutex > aGuard( *GetYieldMutex() );
@@ -765,6 +780,20 @@ void AquaSalInstance::GetPrinterQueueInfo( 
ImplPrnQueueList* pList )
             pList->Add( std::move(pInfo) );
         }
     }
+
+    // tdf#151700 Prevent the non-native LibreOffice PrintDialog from
+    // displaying by creating a fake printer if there are no printers. This
+    // will allow the LibreOffice printing code to proceed with native
+    // NSPrintOperation which will display the native print panel.
+    if ( !nNameCount )
+    {
+        std::unique_ptr<SalPrinterQueueInfo> pInfo(new SalPrinterQueueInfo);
+        pInfo->maPrinterName    = getFallbackPrinterName();
+        pInfo->mnStatus         = PrintQueueFlags::NONE;
+        pInfo->mnJobs           = 0;
+
+        pList->Add( std::move(pInfo) );
+    }
 }
 
 void AquaSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* )
@@ -776,7 +805,9 @@ OUString AquaSalInstance::GetDefaultPrinter()
     // #i113170# may not be the main thread if called from UNO API
     SalData::ensureThreadAutoreleasePool();
 
-    if( maDefaultPrinter.isEmpty() )
+    // WinSalInstance::GetDefaultPrinter() fetches current default printer
+    // on every call so do the same here
+    OUString aDefaultPrinter;
     {
         NSPrintInfo* pPI = [NSPrintInfo sharedPrintInfo];
         SAL_WARN_IF( !pPI, "vcl", "no print info" );
@@ -786,13 +817,20 @@ OUString AquaSalInstance::GetDefaultPrinter()
             SAL_WARN_IF( !pPr, "vcl", "no printer in default info" );
             if( pPr )
             {
+                // Related: tdf#151700 Return the name of the fake printer if
+                // there are no printers so that the LibreOffice printing code
+                // will be able to find the the fake printer returned by
+                // AquaSalInstance::GetPrinterQueueInfo()
                 NSString* pDefName = [pPr name];
                 SAL_WARN_IF( !pDefName, "vcl", "printer has no name" );
-                maDefaultPrinter = GetOUString( pDefName );
+                if ( pDefName && [pDefName length])
+                    aDefaultPrinter = GetOUString( pDefName );
+                else
+                    aDefaultPrinter = getFallbackPrinterName();
             }
         }
     }
-    return maDefaultPrinter;
+    return aDefaultPrinter;
 }
 
 SalInfoPrinter* AquaSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* 
pQueueInfo,
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index e8acbcd38297..dc2fc5e74d35 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -538,6 +538,16 @@ bool 
Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
         {
         }
     }
+#ifdef MACOSX
+    else
+    {
+        // The PrintDialog updates the printer list in its constructor so do
+        // the same for printers that bring up their own dialog since. Not
+        // sure if this is needed or not on Windows or X11, so limit only to
+        // macOS for now.
+        Printer::updatePrinters();
+    }
+#endif
 
     xController->pushPropertiesToPrinter();
     return true;
commit d491791dad8c3a946dac8c4dfd28ef0c4cb65ce5
Author:     Patrick Luby <plub...@neooffice.org>
AuthorDate: Sun Dec 11 14:41:15 2022 -0500
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Tue Dec 13 06:08:40 2022 +0000

    Fix infinite loop in sw_ooxmlexport17 unit test on macOS Intel
    
    When running the sw_ooxmlexport17 unit test on slower macOS Intel
    machines, This loop will never end even after 1M+ loops so set a
    maximum number of loops like is done in the nested while loops.
    
    Change-Id: If3a6140e03f21f4a16f6d90be7988c28c8f36753
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143947
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx
index 75662f3374e0..971d2761639e 100644
--- a/sw/source/core/layout/layact.cxx
+++ b/sw/source/core/layout/layact.cxx
@@ -500,8 +500,20 @@ void SwLayAction::InternalAction(OutputDevice* 
pRenderContext)
         return bAgain;
     };
 
+    int nOuterLoopControlRuns = 0;
+    const int nOutermoopControlMax = 10000;
     while ( (pPage && !IsInterrupt()) || m_nCheckPageNum != USHRT_MAX )
     {
+        // Fix infinite loop in sw_ooxmlexport17 unit test
+        // When running the sw_ooxmlexport17 unit test on slower macOS Intel
+        // machines, This loop will never end even after 1M+ loops so set a
+        // maximum number of loops like is done in the nested while loops.
+        if (++nOuterLoopControlRuns > nOutermoopControlMax)
+        {
+            SAL_WARN("sw", "SwLayAction::InternalAction has run too many 
loops");
+            m_bInterrupt = true;
+        }
+
         // note: this is the only place that consumes and resets 
m_nCheckPageNum
         if ((IsInterrupt() || !pPage) && m_nCheckPageNum != USHRT_MAX)
         {

Reply via email to