diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-10-22 15:58:31 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-10-23 15:21:24 +0200 |
commit | d5d96e04ad8014f3e68351ccb54221d9610b565b (patch) | |
tree | 3e8ac0f0082dbadac30b66fa5d04235e20d649fb /sfx2 | |
parent | 8f06d4b34661411db5c6fd78c4c6c702557cf344 (diff) |
Add document-level option to lock down printing
Change-Id: I85694021d74be79293079d04d5ba1d9b48cfa557
Reviewed-on: https://gerrit.libreoffice.org/81340
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/appuno.cxx | 18 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 53 |
3 files changed, 55 insertions, 21 deletions
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx index 6e5965770710..79247883dcfc 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -171,6 +171,7 @@ static char const sFilterProvider[] = "FilterProvider"; static char const sImageFilter[] = "ImageFilter"; static char const sLockContentExtraction[] = "LockContentExtraction"; static char const sLockExport[] = "LockExport"; +static char const sLockPrint[] = "LockPrint"; static bool isMediaDescriptor( sal_uInt16 nSlotId ) { @@ -861,6 +862,14 @@ void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::Propert if (bOK) rSet.Put( SfxBoolItem( SID_LOCK_EXPORT, bVal ) ); } + else if (aName == sLockPrint) + { + bool bVal = false; + bool bOK = (rProp.Value >>= bVal); + DBG_ASSERT( bOK, "invalid type for LockPrint" ); + if (bOK) + rSet.Put( SfxBoolItem( SID_LOCK_PRINT, bVal ) ); + } #ifdef DBG_UTIL else --nFoundArgs; @@ -1082,6 +1091,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b nAdditional++; if ( rSet.GetItemState( SID_LOCK_EXPORT ) == SfxItemState::SET ) nAdditional++; + if ( rSet.GetItemState( SID_LOCK_PRINT ) == SfxItemState::SET ) + nAdditional++; // consider additional arguments nProps += nAdditional; @@ -1243,6 +1254,8 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b continue; if ( nId == SID_LOCK_EXPORT ) continue; + if ( nId == SID_LOCK_PRINT ) + continue; } OString aDbg = "Unknown item detected: " + OString::number(static_cast<sal_Int32>(nId)); @@ -1645,6 +1658,11 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b pValue[nActProp].Name = sLockExport; pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ; } + if ( rSet.GetItemState( SID_LOCK_PRINT, false, &pItem ) == SfxItemState::SET ) + { + pValue[nActProp].Name = sLockPrint; + pValue[nActProp++].Value <<= static_cast<const SfxBoolItem*>(pItem)->GetValue() ; + } } rArgs = aSequ; diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index bb6a1484befd..67bacd79502d 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -1084,6 +1084,11 @@ void SAL_CALL SfxBaseModel::setArgs(const Sequence<beans::PropertyValue>& aArgs) rArg.Value >>= bValue; pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_EXPORT, bValue)); } + else if (rArg.Name == "LockPrint") + { + rArg.Value >>= bValue; + pMedium->GetItemSet()->Put(SfxBoolItem(SID_LOCK_PRINT, bValue)); + } else { throw lang::IllegalArgumentException("Setting property not supported: " + rArg.Name, diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index e8638badac64..123aa18dcb58 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -700,32 +700,34 @@ void SfxViewShell::GetState_Impl( SfxItemSet &rSet ) case SID_SETUPPRINTER: case SID_PRINTER_NAME: { - bool bEnabled = !Application::GetSettings().GetMiscSettings().GetDisablePrinting(); - if ( bEnabled ) + if (Application::GetSettings().GetMiscSettings().GetDisablePrinting() || isPrintLocked()) { - SfxPrinter *pPrinter = GetPrinter(); + rSet.DisableItem(nSID); + break; + } + + SfxPrinter *pPrinter = GetPrinter(); - if ( SID_PRINTDOCDIRECT == nSID ) + if ( SID_PRINTDOCDIRECT == nSID ) + { + OUString aPrinterName; + if ( pPrinter != nullptr ) + aPrinterName = pPrinter->GetName(); + else + aPrinterName = Printer::GetDefaultPrinterName(); + if ( !aPrinterName.isEmpty() ) { - OUString aPrinterName; - if ( pPrinter != nullptr ) - aPrinterName = pPrinter->GetName(); - else - aPrinterName = Printer::GetDefaultPrinterName(); - if ( !aPrinterName.isEmpty() ) - { - uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); + uno::Reference < frame::XFrame > xFrame( pFrame->GetFrame().GetFrameInterface() ); - OUStringBuffer aBuffer( 60 ); - aBuffer.append( vcl::CommandInfoProvider::GetLabelForCommand( - ".uno:PrintDefault", - vcl::CommandInfoProvider::GetModuleIdentifier( xFrame ) ) ); - aBuffer.append( " (" ); - aBuffer.append( aPrinterName ); - aBuffer.append(')'); + OUStringBuffer aBuffer( 60 ); + aBuffer.append( vcl::CommandInfoProvider::GetLabelForCommand( + ".uno:PrintDefault", + vcl::CommandInfoProvider::GetModuleIdentifier( xFrame ) ) ); + aBuffer.append( " (" ); + aBuffer.append( aPrinterName ); + aBuffer.append(')'); - rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) ); - } + rSet.Put( SfxStringItem( SID_PRINTDOCDIRECT, aBuffer.makeStringAndClear() ) ); } } break; @@ -1765,6 +1767,15 @@ bool SfxViewShell::isExportLocked() return aArgs.getOrDefault("LockExport", false); } +bool SfxViewShell::isPrintLocked() +{ + Reference<XModel> xModel = GetCurrentDocument(); + if (!xModel.is()) + return false; + comphelper::NamedValueCollection aArgs(xModel->getArgs()); + return aArgs.getOrDefault("LockPrint", false); +} + Reference < XController > SfxViewShell::GetController() const { return pImpl->m_pController.get(); |