diff options
author | Patrick Luby <plubius@neooffice.org> | 2022-12-07 11:40:18 -0500 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-12-13 06:08:54 +0000 |
commit | 229b0ce8d8453960c213da59770b8bb7b6dca895 (patch) | |
tree | d8ec53e056c16521904ad48885fd744e82d9c447 /vcl/osx/salinst.cxx | |
parent | d491791dad8c3a946dac8c4dfd28ef0c4cb65ce5 (diff) |
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.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/osx/salinst.cxx')
-rw-r--r-- | vcl/osx/salinst.cxx | 44 |
1 files changed, 41 insertions, 3 deletions
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, |